pdecsub.pas 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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 pdecsub;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. tokens,symconst,symtype,symdef,symsym;
  23. type
  24. tpdflag=(
  25. pd_body, { directive needs a body }
  26. pd_implemen, { directive can be used implementation section }
  27. pd_interface, { directive can be used interface section }
  28. pd_object, { directive can be used object declaration }
  29. pd_procvar, { directive can be used procvar declaration }
  30. pd_notobject, { directive can not be used object declaration }
  31. pd_notobjintf, { directive can not be used interface declaration }
  32. pd_notprocvar { directive can not be used procvar declaration }
  33. );
  34. tpdflags=set of tpdflag;
  35. function is_proc_directive(tok:ttoken;isprocvar:boolean):boolean;
  36. procedure calc_parast(pd:tabstractprocdef);
  37. procedure insert_funcret_local(pd:tprocdef);
  38. function proc_add_definition(var pd:tprocdef):boolean;
  39. procedure handle_calling_convention(pd:tabstractprocdef);
  40. procedure parse_parameter_dec(pd:tabstractprocdef);
  41. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  42. procedure parse_var_proc_directives(sym:tsym);
  43. procedure parse_object_proc_directives(pd:tabstractprocdef);
  44. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  45. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  46. implementation
  47. uses
  48. {$ifdef delphi}
  49. sysutils,
  50. {$else delphi}
  51. strings,
  52. {$endif delphi}
  53. { common }
  54. cutils,cclasses,
  55. { global }
  56. globtype,globals,verbose,
  57. systems,
  58. cpuinfo,
  59. { aasm }
  60. aasmbase,
  61. { symtable }
  62. symbase,symtable,defutil,defcmp,paramgr,
  63. { pass 1 }
  64. node,htypechk,
  65. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,
  66. { parser }
  67. fmodule,scanner,
  68. pbase,pexpr,ptype,pdecl,
  69. { linking }
  70. import,gendef
  71. ;
  72. const
  73. { Please leave this here, this module should NOT use
  74. these variables.
  75. Declaring it as string here results in an error when compiling (PFV) }
  76. current_procinfo = 'error';
  77. procedure insert_funcret_para(pd:tabstractprocdef);
  78. var
  79. storepos : tfileposinfo;
  80. vs : tvarsym;
  81. begin
  82. if not is_void(pd.rettype.def) and
  83. paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  84. begin
  85. storepos:=akttokenpos;
  86. if pd.deftype=procdef then
  87. akttokenpos:=tprocdef(pd).fileinfo;
  88. { Generate result variable accessing function result }
  89. vs:=tvarsym.create('$result',vs_var,pd.rettype);
  90. include(vs.varoptions,vo_is_funcret);
  91. include(vs.varoptions,vo_regable);
  92. pd.parast.insert(vs);
  93. { For left to right add it at the end to be delphi compatible }
  94. if pd.proccalloption in pushleftright_pocalls then
  95. pd.concatpara(nil,vs.vartype,vs,nil,true)
  96. else
  97. pd.insertpara(vs.vartype,vs,nil,true);
  98. { Store the this symbol as funcretsym for procedures }
  99. if pd.deftype=procdef then
  100. tprocdef(pd).funcretsym:=vs;
  101. akttokenpos:=storepos;
  102. end;
  103. end;
  104. procedure insert_parentfp_para(pd:tabstractprocdef);
  105. var
  106. storepos : tfileposinfo;
  107. vs : tvarsym;
  108. begin
  109. if pd.parast.symtablelevel>normal_function_level then
  110. begin
  111. storepos:=akttokenpos;
  112. if pd.deftype=procdef then
  113. akttokenpos:=tprocdef(pd).fileinfo;
  114. { Generate result variable accessing function result }
  115. vs:=tvarsym.create('$parentfp',vs_var,voidpointertype);
  116. include(vs.varoptions,vo_is_parentfp);
  117. pd.parast.insert(vs);
  118. pd.insertpara(vs.vartype,vs,nil,true);
  119. akttokenpos:=storepos;
  120. end;
  121. end;
  122. procedure insert_self_and_vmt_para(pd:tabstractprocdef);
  123. var
  124. storepos : tfileposinfo;
  125. vs : tvarsym;
  126. tt : ttype;
  127. vsp : tvarspez;
  128. begin
  129. if (pd.deftype=procvardef) and
  130. pd.is_methodpointer then
  131. begin
  132. { Generate self variable }
  133. tt:=voidpointertype;
  134. vs:=tvarsym.create('$self',vs_value,tt);
  135. include(vs.varoptions,vo_is_self);
  136. { Insert as hidden parameter }
  137. pd.parast.insert(vs);
  138. pd.insertpara(vs.vartype,vs,nil,true);
  139. end
  140. else
  141. begin
  142. if (pd.deftype=procdef) and
  143. assigned(tprocdef(pd)._class) and
  144. (pd.parast.symtablelevel=normal_function_level) then
  145. begin
  146. storepos:=akttokenpos;
  147. akttokenpos:=tprocdef(pd).fileinfo;
  148. { Generate VMT variable for constructor/destructor }
  149. if pd.proctypeoption in [potype_constructor,potype_destructor] then
  150. begin
  151. { can't use classrefdef as type because inheriting
  152. will then always file because of a type mismatch }
  153. tt:=voidpointertype;
  154. vs:=tvarsym.create('$vmt',vs_value,tt);
  155. include(vs.varoptions,vo_is_vmt);
  156. { Insert as hidden parameter }
  157. pd.parast.insert(vs);
  158. pd.insertpara(vs.vartype,vs,nil,true);
  159. end;
  160. { Generate self variable, for classes we need
  161. to use the generic voidpointer to be compatible with
  162. methodpointers }
  163. vsp:=vs_value;
  164. if (po_staticmethod in pd.procoptions) or
  165. (po_classmethod in pd.procoptions) then
  166. begin
  167. tt.setdef(tprocdef(pd)._class);
  168. tt.setdef(tclassrefdef.create(tt));
  169. end
  170. else
  171. begin
  172. if is_object(tprocdef(pd)._class) then
  173. vsp:=vs_var;
  174. tt.setdef(tprocdef(pd)._class);
  175. end;
  176. vs:=tvarsym.create('$self',vsp,tt);
  177. include(vs.varoptions,vo_is_self);
  178. include(vs.varoptions,vo_regable);
  179. { Insert as hidden parameter }
  180. pd.parast.insert(vs);
  181. pd.insertpara(vs.vartype,vs,nil,true);
  182. akttokenpos:=storepos;
  183. end;
  184. end;
  185. end;
  186. procedure insert_funcret_local(pd:tprocdef);
  187. var
  188. storepos : tfileposinfo;
  189. vs : tvarsym;
  190. sl : tsymlist;
  191. begin
  192. if not is_void(pd.rettype.def) then
  193. begin
  194. storepos:=akttokenpos;
  195. akttokenpos:=pd.fileinfo;
  196. { We always need a localsymtable }
  197. if not assigned(pd.localst) then
  198. pd.insert_localst;
  199. { We need to insert a varsym for the result in the localst
  200. when it is returning in a register }
  201. if not paramanager.ret_in_param(pd.rettype.def,pd.proccalloption) then
  202. begin
  203. vs:=tvarsym.create('$result',vs_value,pd.rettype);
  204. include(vs.varoptions,vo_is_funcret);
  205. if tstoreddef(pd.rettype.def).is_intregable then
  206. include(vs.varoptions,vo_regable);
  207. if tstoreddef(pd.rettype.def).is_fpuregable then
  208. include(vs.varoptions,vo_fpuregable);
  209. pd.localst.insert(vs);
  210. pd.funcretsym:=vs;
  211. end;
  212. { insert the name of the procedure as alias for the function result,
  213. we can't use realname because that will not work for compilerprocs
  214. as the name is lowercase and unreachable from the code }
  215. if pd.resultname='' then
  216. pd.resultname:=pd.procsym.name;
  217. sl:=tsymlist.create;
  218. sl.addsym(sl_load,pd.funcretsym);
  219. vs:=tabsolutesym.create_ref(pd.resultname,pd.rettype,sl);
  220. include(vs.varoptions,vo_is_funcret);
  221. pd.localst.insert(vs);
  222. { insert result also if support is on }
  223. if (m_result in aktmodeswitches) then
  224. begin
  225. sl:=tsymlist.create;
  226. sl.addsym(sl_load,pd.funcretsym);
  227. vs:=tabsolutesym.create_ref('RESULT',pd.rettype,sl);
  228. include(vs.varoptions,vo_is_funcret);
  229. include(vs.varoptions,vo_is_result);
  230. pd.localst.insert(vs);
  231. end;
  232. akttokenpos:=storepos;
  233. end;
  234. end;
  235. procedure insert_hidden_para(pd:tabstractprocdef);
  236. var
  237. currpara : tparaitem;
  238. hvs : tvarsym;
  239. begin
  240. { walk from right to left, so we can insert the
  241. high parameters after the current parameter }
  242. currpara:=tparaitem(pd.para.last);
  243. while assigned(currpara) do
  244. begin
  245. { needs high parameter ? }
  246. if paramanager.push_high_param(currpara.paratyp,currpara.paratype.def,pd.proccalloption) then
  247. begin
  248. if assigned(currpara.parasym) then
  249. begin
  250. hvs:=tvarsym.create('$high'+tvarsym(currpara.parasym).name,vs_const,s32inttype);
  251. include(hvs.varoptions,vo_is_high_value);
  252. tvarsym(currpara.parasym).owner.insert(hvs);
  253. end
  254. else
  255. hvs:=nil;
  256. pd.concatpara(currpara,s32inttype,hvs,nil,true);
  257. end
  258. else
  259. begin
  260. { Give a warning that cdecl routines does not include high()
  261. support }
  262. if (pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) and
  263. paramanager.push_high_param(currpara.paratyp,currpara.paratype.def,pocall_default) then
  264. begin
  265. if is_open_string(currpara.paratype.def) then
  266. Message(parser_w_cdecl_no_openstring);
  267. if not (po_external in pd.procoptions) then
  268. Message(parser_w_cdecl_has_no_high);
  269. end;
  270. end;
  271. currpara:=tparaitem(currpara.previous);
  272. end;
  273. end;
  274. procedure check_c_para(p:tnamedindexitem;arg:pointer);
  275. begin
  276. if (tsym(p).typ<>varsym) then
  277. exit;
  278. with tvarsym(p) do
  279. begin
  280. case vartype.def.deftype of
  281. arraydef :
  282. begin
  283. if not is_variant_array(vartype.def) and
  284. not is_array_of_const(vartype.def) then
  285. begin
  286. if (varspez<>vs_var) then
  287. Message(parser_h_c_arrays_are_references);
  288. end;
  289. if is_array_of_const(vartype.def) and
  290. assigned(indexnext) and
  291. (tsym(indexnext).typ=varsym) and
  292. not(vo_is_high_value in tvarsym(indexnext).varoptions) then
  293. Message(parser_e_C_array_of_const_must_be_last);
  294. end;
  295. end;
  296. end;
  297. end;
  298. procedure parse_parameter_dec(pd:tabstractprocdef);
  299. {
  300. handle_procvar needs the same changes
  301. }
  302. var
  303. is_procvar : boolean;
  304. sc : tsinglelist;
  305. tt : ttype;
  306. arrayelementtype : ttype;
  307. vs : tvarsym;
  308. srsym : tsym;
  309. hs1 : string;
  310. varspez : Tvarspez;
  311. defaultvalue : tconstsym;
  312. defaultrequired : boolean;
  313. old_object_option : tsymoptions;
  314. currparast : tparasymtable;
  315. explicit_paraloc : boolean;
  316. locationstr : string;
  317. begin
  318. explicit_paraloc:=false;
  319. consume(_LKLAMMER);
  320. { Delphi/Kylix supports nonsense like }
  321. { procedure p(); }
  322. if try_to_consume(_RKLAMMER) and
  323. not(m_tp7 in aktmodeswitches) then
  324. exit;
  325. { parsing a proc or procvar ? }
  326. is_procvar:=(pd.deftype=procvardef);
  327. currparast:=tparasymtable(pd.parast);
  328. { reset }
  329. sc:=tsinglelist.create;
  330. defaultrequired:=false;
  331. { the variables are always public }
  332. old_object_option:=current_object_option;
  333. current_object_option:=[sp_public];
  334. inc(testcurobject);
  335. repeat
  336. if try_to_consume(_VAR) then
  337. varspez:=vs_var
  338. else
  339. if try_to_consume(_CONST) then
  340. varspez:=vs_const
  341. else
  342. if (idtoken=_OUT) and (m_out in aktmodeswitches) then
  343. begin
  344. consume(_OUT);
  345. varspez:=vs_out
  346. end
  347. else
  348. varspez:=vs_value;
  349. defaultvalue:=nil;
  350. tt.reset;
  351. { read identifiers and insert with error type }
  352. sc.reset;
  353. repeat
  354. vs:=tvarsym.create(orgpattern,varspez,generrortype);
  355. currparast.insert(vs);
  356. if assigned(vs.owner) then
  357. sc.insert(vs)
  358. else
  359. vs.free;
  360. consume(_ID);
  361. until not try_to_consume(_COMMA);
  362. { read type declaration, force reading for value and const paras }
  363. if (token=_COLON) or (varspez=vs_value) then
  364. begin
  365. consume(_COLON);
  366. { check for an open array }
  367. if token=_ARRAY then
  368. begin
  369. consume(_ARRAY);
  370. consume(_OF);
  371. { define range and type of range }
  372. tt.setdef(tarraydef.create(0,-1,s32inttype));
  373. { array of const ? }
  374. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  375. begin
  376. consume(_CONST);
  377. srsym:=searchsymonlyin(systemunit,'TVARREC');
  378. if not assigned(srsym) then
  379. InternalError(200404181);
  380. tarraydef(tt.def).setelementtype(ttypesym(srsym).restype);
  381. tarraydef(tt.def).IsArrayOfConst:=true;
  382. end
  383. else
  384. begin
  385. { define field type }
  386. single_type(arrayelementtype,hs1,false);
  387. tarraydef(tt.def).setelementtype(arrayelementtype);
  388. end;
  389. end
  390. else
  391. begin
  392. { open string ? }
  393. if (varspez=vs_var) and
  394. (
  395. (
  396. ((token=_STRING) or (idtoken=_SHORTSTRING)) and
  397. (cs_openstring in aktmoduleswitches) and
  398. not(cs_ansistrings in aktlocalswitches)
  399. ) or
  400. (idtoken=_OPENSTRING)) then
  401. begin
  402. consume(token);
  403. tt:=openshortstringtype;
  404. hs1:='openstring';
  405. end
  406. else
  407. begin
  408. { everything else }
  409. single_type(tt,hs1,false);
  410. end;
  411. if (target_info.system in [system_powerpc_morphos]) then
  412. begin
  413. if (idtoken=_LOCATION) then
  414. begin
  415. consume(_LOCATION);
  416. locationstr:=pattern;
  417. consume(_CSTRING);
  418. end
  419. else
  420. begin
  421. if explicit_paraloc then
  422. Message(parser_e_paraloc_all_paras);
  423. locationstr:='';
  424. end;
  425. end
  426. else
  427. locationstr:='';
  428. { default parameter }
  429. if (m_default_para in aktmodeswitches) then
  430. begin
  431. if try_to_consume(_EQUAL) then
  432. begin
  433. vs:=tvarsym(sc.first);
  434. if assigned(vs.listnext) then
  435. Message(parser_e_default_value_only_one_para);
  436. { prefix 'def' to the parameter name }
  437. defaultvalue:=ReadConstant('$def'+vs.name,vs.fileinfo);
  438. include(defaultvalue.symoptions,sp_internal);
  439. if assigned(defaultvalue) then
  440. tprocdef(pd).parast.insert(defaultvalue);
  441. defaultrequired:=true;
  442. end
  443. else
  444. begin
  445. if defaultrequired then
  446. Message1(parser_e_default_value_expected_for_para,vs.name);
  447. end;
  448. end;
  449. end;
  450. end
  451. else
  452. begin
  453. {$ifndef UseNiceNames}
  454. hs1:='$$$';
  455. {$else UseNiceNames}
  456. hs1:='var';
  457. {$endif UseNiceNames}
  458. tt:=cformaltype;
  459. end;
  460. { File types are only allowed for var parameters }
  461. if (tt.def.deftype=filedef) and
  462. (varspez<>vs_var) then
  463. CGMessage(cg_e_file_must_call_by_reference);
  464. vs:=tvarsym(sc.first);
  465. while assigned(vs) do
  466. begin
  467. { update varsym }
  468. vs.vartype:=tt;
  469. { For proc vars we only need the definitions }
  470. if not is_procvar then
  471. begin
  472. if (varspez in [vs_var,vs_const,vs_out]) and
  473. paramanager.push_addr_param(varspez,tt.def,pd.proccalloption) then
  474. include(vs.varoptions,vo_regable);
  475. end;
  476. pd.concatpara(nil,tt,vs,defaultvalue,false);
  477. if (target_info.system in [system_powerpc_morphos]) then
  478. begin
  479. if locationstr<>'' then
  480. begin
  481. if assigned(sc.first.listnext) then
  482. Message(parser_e_paraloc_only_one_para);
  483. if (pd.para.first<>pd.para.last) and not(explicit_paraloc) then
  484. Message(parser_e_paraloc_all_paras);
  485. explicit_paraloc:=true;
  486. if not(paramanager.parseparaloc(tparaitem(pd.para.last),upper(locationstr))) then
  487. message(parser_e_illegal_explicit_paraloc);
  488. end
  489. else
  490. if explicit_paraloc then
  491. Message(parser_e_paraloc_all_paras);
  492. end;
  493. vs:=tvarsym(vs.listnext);
  494. end;
  495. until not try_to_consume(_SEMICOLON);
  496. if explicit_paraloc then
  497. begin
  498. pd.has_paraloc_info:=true;
  499. include(pd.procoptions,po_explicitparaloc);
  500. end;
  501. { remove parasymtable from stack }
  502. sc.free;
  503. { reset object options }
  504. dec(testcurobject);
  505. current_object_option:=old_object_option;
  506. consume(_RKLAMMER);
  507. end;
  508. function parse_proc_head(aclass:tobjectdef;potype:tproctypeoption;var pd:tprocdef):boolean;
  509. var
  510. orgsp,sp : stringid;
  511. sym : tsym;
  512. srsymtable : tsymtable;
  513. storepos,
  514. procstartfilepos : tfileposinfo;
  515. searchagain : boolean;
  516. i : longint;
  517. st : tsymtable;
  518. aprocsym : tprocsym;
  519. begin
  520. { Save the position where this procedure really starts }
  521. procstartfilepos:=akttokenpos;
  522. result:=false;
  523. pd:=nil;
  524. aprocsym:=nil;
  525. if (potype=potype_operator) then
  526. begin
  527. sp:=overloaded_names[optoken];
  528. orgsp:=sp;
  529. end
  530. else
  531. begin
  532. sp:=pattern;
  533. orgsp:=orgpattern;
  534. consume(_ID);
  535. end;
  536. { examine interface map: function/procedure iname.functionname=locfuncname }
  537. if assigned(aclass) and
  538. assigned(aclass.implementedinterfaces) and
  539. (aclass.implementedinterfaces.count>0) and
  540. try_to_consume(_POINT) then
  541. begin
  542. storepos:=akttokenpos;
  543. akttokenpos:=procstartfilepos;
  544. { get interface syms}
  545. searchsym(sp,sym,srsymtable);
  546. if not assigned(sym) then
  547. begin
  548. identifier_not_found(orgsp);
  549. sym:=generrorsym;
  550. end;
  551. akttokenpos:=storepos;
  552. { qualifier is interface? }
  553. if (sym.typ=typesym) and
  554. (ttypesym(sym).restype.def.deftype=objectdef) then
  555. i:=aclass.implementedinterfaces.searchintf(ttypesym(sym).restype.def)
  556. else
  557. i:=-1;
  558. if (i=-1) then
  559. Message(parser_e_interface_id_expected);
  560. consume(_ID);
  561. consume(_EQUAL);
  562. if (token=_ID) then
  563. aclass.implementedinterfaces.addmappings(i,sp,pattern);
  564. consume(_ID);
  565. result:=true;
  566. exit;
  567. end;
  568. { method ? }
  569. if not assigned(aclass) and
  570. (potype<>potype_operator) and
  571. (symtablestack.symtablelevel=main_program_level) and
  572. try_to_consume(_POINT) then
  573. begin
  574. { search for object name }
  575. storepos:=akttokenpos;
  576. akttokenpos:=procstartfilepos;
  577. searchsym(sp,sym,srsymtable);
  578. if not assigned(sym) then
  579. begin
  580. identifier_not_found(orgsp);
  581. sym:=generrorsym;
  582. end;
  583. akttokenpos:=storepos;
  584. { consume proc name }
  585. sp:=pattern;
  586. orgsp:=orgpattern;
  587. procstartfilepos:=akttokenpos;
  588. consume(_ID);
  589. { qualifier is class name ? }
  590. if (sym.typ=typesym) and
  591. (ttypesym(sym).restype.def.deftype=objectdef) then
  592. begin
  593. aclass:=tobjectdef(ttypesym(sym).restype.def);
  594. aprocsym:=tprocsym(aclass.symtable.search(sp));
  595. { we solve this below }
  596. if assigned(aprocsym) then
  597. begin
  598. if aprocsym.typ<>procsym then
  599. begin
  600. { we use a different error message for tp7 so it looks more compatible }
  601. if (m_fpc in aktmodeswitches) then
  602. Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
  603. else
  604. Message(parser_e_methode_id_expected);
  605. { rename the name to an unique name to avoid an
  606. error when inserting the symbol in the symtable }
  607. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  608. aprocsym:=nil;
  609. end;
  610. end
  611. else
  612. begin
  613. Message(parser_e_methode_id_expected);
  614. { recover by making it a normal procedure instead of method }
  615. aclass:=nil;
  616. end;
  617. end
  618. else
  619. Message(parser_e_class_id_expected);
  620. end
  621. else
  622. begin
  623. { check for constructor/destructor which is not allowed here }
  624. if (not parse_only) and
  625. (potype in [potype_constructor,potype_destructor]) then
  626. Message(parser_e_constructors_always_objects);
  627. repeat
  628. searchagain:=false;
  629. akttokenpos:=procstartfilepos;
  630. aprocsym:=tprocsym(symtablestack.search(sp));
  631. if not(parse_only) and
  632. not assigned(aprocsym) and
  633. (symtablestack.symtabletype=staticsymtable) and
  634. assigned(symtablestack.next) and
  635. (symtablestack.next.unitid=0) then
  636. begin
  637. { The procedure we prepare for is in the implementation
  638. part of the unit we compile. It is also possible that we
  639. are compiling a program, which is also some kind of
  640. implementaion part.
  641. We need to find out if the procedure is global. If it is
  642. global, it is in the global symtable.}
  643. aprocsym:=tprocsym(symtablestack.next.search(sp));
  644. end;
  645. { Check if overloaded is a procsym }
  646. if assigned(aprocsym) and
  647. (aprocsym.typ<>procsym) then
  648. begin
  649. { when the other symbol is a unit symbol then hide the unit
  650. symbol. Only in tp mode because it's bad programming }
  651. if (m_duplicate_names in aktmodeswitches) and
  652. (aprocsym.typ=unitsym) then
  653. begin
  654. aprocsym.owner.rename(aprocsym.name,'hidden'+aprocsym.name);
  655. searchagain:=true;
  656. end
  657. else
  658. begin
  659. { we use a different error message for tp7 so it looks more compatible }
  660. if (m_fpc in aktmodeswitches) then
  661. Message1(parser_e_overloaded_no_procedure,aprocsym.realname)
  662. else
  663. DuplicateSym(aprocsym);
  664. { rename the name to an unique name to avoid an
  665. error when inserting the symbol in the symtable }
  666. orgsp:=orgsp+'$'+tostr(aktfilepos.line);
  667. { generate a new aktprocsym }
  668. aprocsym:=nil;
  669. end;
  670. end;
  671. until not searchagain;
  672. end;
  673. { test again if assigned, it can be reset to recover }
  674. if not assigned(aprocsym) then
  675. begin
  676. { create a new procsym and set the real filepos }
  677. akttokenpos:=procstartfilepos;
  678. { for operator we have only one procsym for each overloaded
  679. operation }
  680. if (potype=potype_operator) then
  681. begin
  682. Aprocsym:=Tprocsym(symtablestack.search(sp));
  683. if Aprocsym=nil then
  684. Aprocsym:=tprocsym.create('$'+sp);
  685. end
  686. else
  687. aprocsym:=tprocsym.create(orgsp);
  688. symtablestack.insert(aprocsym);
  689. end;
  690. { to get the correct symtablelevel we must ignore objectsymtables }
  691. st:=symtablestack;
  692. while not(st.symtabletype in [staticsymtable,globalsymtable,localsymtable]) do
  693. st:=st.next;
  694. pd:=tprocdef.create(st.symtablelevel+1);
  695. pd._class:=aclass;
  696. pd.procsym:=aprocsym;
  697. pd.proctypeoption:=potype;
  698. { methods need to be exported }
  699. if assigned(aclass) and
  700. (
  701. (symtablestack.symtabletype=objectsymtable) or
  702. (symtablestack.symtablelevel=main_program_level)
  703. ) then
  704. include(pd.procoptions,po_public);
  705. { symbol options that need to be kept per procdef }
  706. pd.fileinfo:=procstartfilepos;
  707. pd.symoptions:=current_object_option;
  708. { parse parameters }
  709. if token=_LKLAMMER then
  710. parse_parameter_dec(pd);
  711. result:=true;
  712. end;
  713. function parse_proc_dec(aclass:tobjectdef):tprocdef;
  714. var
  715. pd : tprocdef;
  716. hs : string;
  717. isclassmethod : boolean;
  718. begin
  719. pd:=nil;
  720. { read class method }
  721. if try_to_consume(_CLASS) then
  722. begin
  723. { class method only allowed for procedures and functions }
  724. if not(token in [_FUNCTION,_PROCEDURE]) then
  725. Message(parser_e_procedure_or_function_expected);
  726. isclassmethod:=true;
  727. end
  728. else
  729. isclassmethod:=false;
  730. case token of
  731. _FUNCTION :
  732. begin
  733. consume(_FUNCTION);
  734. if parse_proc_head(aclass,potype_none,pd) then
  735. begin
  736. { pd=nil when it is a interface mapping }
  737. if assigned(pd) then
  738. begin
  739. if try_to_consume(_COLON) then
  740. begin
  741. inc(testcurobject);
  742. single_type(pd.rettype,hs,false);
  743. pd.test_if_fpu_result;
  744. dec(testcurobject);
  745. end
  746. else
  747. begin
  748. if (
  749. not(is_interface(pd._class)) and
  750. not(pd.forwarddef)
  751. ) or
  752. (m_repeat_forward in aktmodeswitches) then
  753. begin
  754. consume(_COLON);
  755. consume_all_until(_SEMICOLON);
  756. end;
  757. end;
  758. if isclassmethod then
  759. include(pd.procoptions,po_classmethod);
  760. end;
  761. end
  762. else
  763. begin
  764. { recover }
  765. consume(_COLON);
  766. consume_all_until(_SEMICOLON);
  767. end;
  768. end;
  769. _PROCEDURE :
  770. begin
  771. consume(_PROCEDURE);
  772. if parse_proc_head(aclass,potype_none,pd) then
  773. begin
  774. { pd=nil when it is a interface mapping }
  775. if assigned(pd) then
  776. begin
  777. pd.rettype:=voidtype;
  778. if isclassmethod then
  779. include(pd.procoptions,po_classmethod);
  780. end;
  781. end;
  782. end;
  783. _CONSTRUCTOR :
  784. begin
  785. consume(_CONSTRUCTOR);
  786. parse_proc_head(aclass,potype_constructor,pd);
  787. if assigned(pd) and
  788. assigned(pd._class) then
  789. begin
  790. { Set return type, class constructors return the
  791. created instance, object constructors return boolean }
  792. if is_class(pd._class) then
  793. pd.rettype.setdef(pd._class)
  794. else
  795. pd.rettype:=booltype;
  796. end;
  797. end;
  798. _DESTRUCTOR :
  799. begin
  800. consume(_DESTRUCTOR);
  801. parse_proc_head(aclass,potype_destructor,pd);
  802. if assigned(pd) then
  803. pd.rettype:=voidtype;
  804. end;
  805. _OPERATOR :
  806. begin
  807. consume(_OPERATOR);
  808. if (token in [first_overloaded..last_overloaded]) then
  809. begin
  810. optoken:=token;
  811. end
  812. else
  813. begin
  814. Message(parser_e_overload_operator_failed);
  815. { Use the dummy NOTOKEN that is also declared
  816. for the overloaded_operator[] }
  817. optoken:=NOTOKEN;
  818. end;
  819. consume(token);
  820. parse_proc_head(aclass,potype_operator,pd);
  821. if assigned(pd) then
  822. begin
  823. if pd.parast.symtablelevel>normal_function_level then
  824. Message(parser_e_no_local_operator);
  825. if token<>_ID then
  826. begin
  827. if not(m_result in aktmodeswitches) then
  828. consume(_ID);
  829. end
  830. else
  831. begin
  832. pd.resultname:=orgpattern;
  833. consume(_ID);
  834. end;
  835. if not try_to_consume(_COLON) then
  836. begin
  837. consume(_COLON);
  838. pd.rettype:=generrortype;
  839. consume_all_until(_SEMICOLON);
  840. end
  841. else
  842. begin
  843. single_type(pd.rettype,hs,false);
  844. pd.test_if_fpu_result;
  845. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  846. ((pd.rettype.def.deftype<>orddef) or
  847. (torddef(pd.rettype.def).typ<>bool8bit)) then
  848. Message(parser_e_comparative_operator_return_boolean);
  849. if (optoken=_ASSIGNMENT) and
  850. equal_defs(pd.rettype.def,
  851. tvarsym(pd.parast.symindex.first).vartype.def) then
  852. message(parser_e_no_such_assignment)
  853. else if not isoperatoracceptable(pd,optoken) then
  854. Message(parser_e_overload_impossible);
  855. end;
  856. end
  857. else
  858. begin
  859. { recover }
  860. try_to_consume(_ID);
  861. consume(_COLON);
  862. consume_all_until(_SEMICOLON);
  863. end;
  864. end;
  865. end;
  866. { support procedure proc stdcall export; }
  867. if not(is_proc_directive(token,false)) then
  868. consume(_SEMICOLON);
  869. result:=pd;
  870. end;
  871. {****************************************************************************
  872. Procedure directive handlers
  873. ****************************************************************************}
  874. procedure pd_far(pd:tabstractprocdef);
  875. begin
  876. Message1(parser_w_proc_directive_ignored,'FAR');
  877. end;
  878. procedure pd_near(pd:tabstractprocdef);
  879. begin
  880. Message1(parser_w_proc_directive_ignored,'NEAR');
  881. end;
  882. procedure pd_export(pd:tabstractprocdef);
  883. begin
  884. if pd.deftype<>procdef then
  885. internalerror(200304264);
  886. if assigned(tprocdef(pd)._class) then
  887. Message(parser_e_methods_dont_be_export);
  888. if pd.parast.symtablelevel>normal_function_level then
  889. Message(parser_e_dont_nest_export);
  890. { only os/2 and emx need this }
  891. if target_info.system in [system_i386_os2,system_i386_emx] then
  892. begin
  893. tprocdef(pd).aliasnames.insert(tprocdef(pd).procsym.realname);
  894. if cs_link_deffile in aktglobalswitches then
  895. deffile.AddExport(tprocdef(pd).mangledname);
  896. end;
  897. end;
  898. procedure pd_forward(pd:tabstractprocdef);
  899. begin
  900. if pd.deftype<>procdef then
  901. internalerror(200304265);
  902. tprocdef(pd).forwarddef:=true;
  903. end;
  904. procedure pd_alias(pd:tabstractprocdef);
  905. begin
  906. if pd.deftype<>procdef then
  907. internalerror(200304266);
  908. consume(_COLON);
  909. tprocdef(pd).aliasnames.insert(get_stringconst);
  910. end;
  911. procedure pd_asmname(pd:tabstractprocdef);
  912. begin
  913. if pd.deftype<>procdef then
  914. internalerror(200304267);
  915. tprocdef(pd).setmangledname(target_info.Cprefix+pattern);
  916. if token=_CCHAR then
  917. consume(_CCHAR)
  918. else
  919. consume(_CSTRING);
  920. { we don't need anything else }
  921. tprocdef(pd).forwarddef:=false;
  922. end;
  923. procedure pd_inline(pd:tabstractprocdef);
  924. var
  925. hp : tparaitem;
  926. begin
  927. { check if there is an array of const }
  928. hp:=tparaitem(pd.para.first);
  929. while assigned(hp) do
  930. begin
  931. if assigned(hp.paratype.def) and
  932. (hp.paratype.def.deftype=arraydef) then
  933. begin
  934. with tarraydef(hp.paratype.def) do
  935. if IsVariant or IsConstructor {or IsArrayOfConst} then
  936. begin
  937. Message1(parser_w_not_supported_for_inline,'array of const');
  938. Message(parser_w_inlining_disabled);
  939. pd.proccalloption:=pocall_default;
  940. end;
  941. end;
  942. hp:=tparaitem(hp.next);
  943. end;
  944. end;
  945. procedure pd_intern(pd:tabstractprocdef);
  946. begin
  947. if pd.deftype<>procdef then
  948. internalerror(200304268);
  949. consume(_COLON);
  950. tprocdef(pd).extnumber:=get_intconst;
  951. end;
  952. procedure pd_interrupt(pd:tabstractprocdef);
  953. begin
  954. if pd.parast.symtablelevel>normal_function_level then
  955. Message(parser_e_dont_nest_interrupt);
  956. end;
  957. procedure pd_abstract(pd:tabstractprocdef);
  958. begin
  959. if pd.deftype<>procdef then
  960. internalerror(200304269);
  961. if (po_virtualmethod in pd.procoptions) then
  962. include(pd.procoptions,po_abstractmethod)
  963. else
  964. Message(parser_e_only_virtual_methods_abstract);
  965. { the method is defined }
  966. tprocdef(pd).forwarddef:=false;
  967. end;
  968. procedure pd_virtual(pd:tabstractprocdef);
  969. {$ifdef WITHDMT}
  970. var
  971. pt : tnode;
  972. {$endif WITHDMT}
  973. begin
  974. if pd.deftype<>procdef then
  975. internalerror(2003042610);
  976. if (pd.proctypeoption=potype_constructor) and
  977. is_object(tprocdef(pd)._class) then
  978. Message(parser_e_constructor_cannot_be_not_virtual);
  979. {$ifdef WITHDMT}
  980. if is_object(tprocdef(pd)._class) and
  981. (token<>_SEMICOLON) then
  982. begin
  983. { any type of parameter is allowed here! }
  984. pt:=comp_expr(true);
  985. if is_constintnode(pt) then
  986. begin
  987. include(pd.procoptions,po_msgint);
  988. pd.messageinf.i:=pt^.value;
  989. end
  990. else
  991. Message(parser_e_ill_msg_expr);
  992. disposetree(pt);
  993. end;
  994. {$endif WITHDMT}
  995. end;
  996. procedure pd_static(pd:tabstractprocdef);
  997. begin
  998. if (cs_static_keyword in aktmoduleswitches) then
  999. begin
  1000. if pd.deftype=procdef then
  1001. include(tprocdef(pd).procsym.symoptions,sp_static);
  1002. include(pd.procoptions,po_staticmethod);
  1003. end;
  1004. end;
  1005. procedure pd_override(pd:tabstractprocdef);
  1006. begin
  1007. if pd.deftype<>procdef then
  1008. internalerror(2003042611);
  1009. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1010. Message(parser_e_no_object_override);
  1011. end;
  1012. procedure pd_overload(pd:tabstractprocdef);
  1013. begin
  1014. if pd.deftype<>procdef then
  1015. internalerror(2003042612);
  1016. include(tprocdef(pd).procsym.symoptions,sp_has_overloaded);
  1017. end;
  1018. procedure pd_message(pd:tabstractprocdef);
  1019. var
  1020. pt : tnode;
  1021. begin
  1022. if pd.deftype<>procdef then
  1023. internalerror(2003042613);
  1024. if not is_class(tprocdef(pd)._class) then
  1025. Message(parser_e_msg_only_for_classes);
  1026. { check parameter type }
  1027. if ((pd.minparacount<>1) or
  1028. (pd.maxparacount<>1) or
  1029. (TParaItem(pd.Para.first).paratyp<>vs_var)) then
  1030. Message(parser_e_ill_msg_param);
  1031. pt:=comp_expr(true);
  1032. if pt.nodetype=stringconstn then
  1033. begin
  1034. include(pd.procoptions,po_msgstr);
  1035. tprocdef(pd).messageinf.str:=strnew(tstringconstnode(pt).value_str);
  1036. end
  1037. else
  1038. if is_constintnode(pt) then
  1039. begin
  1040. include(pd.procoptions,po_msgint);
  1041. tprocdef(pd).messageinf.i:=tordconstnode(pt).value;
  1042. end
  1043. else
  1044. Message(parser_e_ill_msg_expr);
  1045. pt.free;
  1046. end;
  1047. procedure pd_reintroduce(pd:tabstractprocdef);
  1048. begin
  1049. if pd.deftype<>procdef then
  1050. internalerror(200401211);
  1051. if not(is_class_or_interface(tprocdef(pd)._class)) then
  1052. Message(parser_e_no_object_reintroduce);
  1053. end;
  1054. procedure pd_syscall(pd:tabstractprocdef);
  1055. begin
  1056. if pd.deftype<>procdef then
  1057. internalerror(2003042614);
  1058. tprocdef(pd).forwarddef:=false;
  1059. tprocdef(pd).extnumber:=get_intconst;
  1060. end;
  1061. procedure pd_external(pd:tabstractprocdef);
  1062. {
  1063. If import_dll=nil the procedure is assumed to be in another
  1064. object file. In that object file it should have the name to
  1065. which import_name is pointing to. Otherwise, the procedure is
  1066. assumed to be in the DLL to which import_dll is pointing to. In
  1067. that case either import_nr<>0 or import_name<>nil is true, so
  1068. the procedure is either imported by number or by name. (DM)
  1069. }
  1070. var
  1071. import_dll,
  1072. import_name : string;
  1073. import_nr : word;
  1074. hpd : tprocdef;
  1075. begin
  1076. if pd.deftype<>procdef then
  1077. internalerror(2003042615);
  1078. tprocdef(pd).forwarddef:=false;
  1079. { forbid local external procedures }
  1080. if pd.parast.symtablelevel>normal_function_level then
  1081. Message(parser_e_no_local_external);
  1082. { If the procedure should be imported from a DLL, a constant string follows.
  1083. This isn't really correct, an contant string expression follows
  1084. so we check if an semicolon follows, else a string constant have to
  1085. follow (FK) }
  1086. import_nr:=0;
  1087. import_name:='';
  1088. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  1089. begin
  1090. import_dll:=get_stringconst;
  1091. if (idtoken=_NAME) then
  1092. begin
  1093. consume(_NAME);
  1094. import_name:=get_stringconst;
  1095. end;
  1096. if (idtoken=_INDEX) then
  1097. begin
  1098. {After the word index follows the index number in the DLL.}
  1099. consume(_INDEX);
  1100. import_nr:=get_intconst;
  1101. end;
  1102. { default is to used the realname of the procedure }
  1103. if (import_nr=0) and (import_name='') then
  1104. import_name:=tprocdef(pd).procsym.realname;
  1105. { create importlib if not already done }
  1106. if not(current_module.uses_imports) then
  1107. begin
  1108. current_module.uses_imports:=true;
  1109. importlib.preparelib(current_module.modulename^);
  1110. end;
  1111. if not(m_repeat_forward in aktmodeswitches) then
  1112. begin
  1113. { we can only have one overloaded here ! }
  1114. if tprocsym(tprocdef(pd).procsym).procdef_count>1 then
  1115. hpd:=tprocsym(tprocdef(pd).procsym).procdef[2]
  1116. else
  1117. hpd:=tprocdef(pd);
  1118. end
  1119. else
  1120. hpd:=tprocdef(pd);
  1121. importlib.importprocedure(hpd,import_dll,import_nr,import_name);
  1122. end
  1123. else
  1124. begin
  1125. if (idtoken=_NAME) then
  1126. begin
  1127. consume(_NAME);
  1128. import_name:=get_stringconst;
  1129. tprocdef(pd).setmangledname(import_name);
  1130. end;
  1131. end;
  1132. end;
  1133. type
  1134. pd_handler=procedure(pd:tabstractprocdef);
  1135. proc_dir_rec=record
  1136. idtok : ttoken;
  1137. pd_flags : tpdflags;
  1138. handler : pd_handler;
  1139. pocall : tproccalloption;
  1140. pooption : tprocoptions;
  1141. mutexclpocall : tproccalloptions;
  1142. mutexclpotype : tproctypeoptions;
  1143. mutexclpo : tprocoptions;
  1144. end;
  1145. const
  1146. {Should contain the number of procedure directives we support.}
  1147. num_proc_directives=35;
  1148. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  1149. (
  1150. (
  1151. idtok:_ABSTRACT;
  1152. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1153. handler : {$ifdef FPCPROCVAR}@{$endif}pd_abstract;
  1154. pocall : pocall_none;
  1155. pooption : [po_abstractmethod];
  1156. mutexclpocall : [pocall_internproc,pocall_inline];
  1157. mutexclpotype : [];
  1158. mutexclpo : [po_exports,po_interrupt,po_external]
  1159. ),(
  1160. idtok:_ALIAS;
  1161. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1162. handler : {$ifdef FPCPROCVAR}@{$endif}pd_alias;
  1163. pocall : pocall_none;
  1164. pooption : [];
  1165. mutexclpocall : [pocall_inline];
  1166. mutexclpotype : [];
  1167. mutexclpo : [po_external]
  1168. ),(
  1169. idtok:_ASMNAME;
  1170. pd_flags : [pd_interface,pd_implemen,pd_notobjintf];
  1171. handler : {$ifdef FPCPROCVAR}@{$endif}pd_asmname;
  1172. pocall : pocall_cdecl;
  1173. pooption : [po_external];
  1174. mutexclpocall : [pocall_internproc,pocall_inline];
  1175. mutexclpotype : [];
  1176. mutexclpo : [po_external]
  1177. ),(
  1178. idtok:_ASSEMBLER;
  1179. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1180. handler : nil;
  1181. pocall : pocall_none;
  1182. pooption : [po_assembler];
  1183. mutexclpocall : [];
  1184. mutexclpotype : [];
  1185. mutexclpo : [po_external]
  1186. ),(
  1187. idtok:_CDECL;
  1188. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1189. handler : nil;
  1190. pocall : pocall_cdecl;
  1191. pooption : [];
  1192. mutexclpocall : [];
  1193. mutexclpotype : [potype_constructor,potype_destructor];
  1194. mutexclpo : [po_assembler,po_external]
  1195. ),(
  1196. idtok:_DYNAMIC;
  1197. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1198. handler : {$ifdef FPCPROCVAR}@{$endif}pd_virtual;
  1199. pocall : pocall_none;
  1200. pooption : [po_virtualmethod];
  1201. mutexclpocall : [pocall_internproc,pocall_inline];
  1202. mutexclpotype : [];
  1203. mutexclpo : [po_exports,po_interrupt,po_external,po_overridingmethod]
  1204. ),(
  1205. idtok:_EXPORT;
  1206. pd_flags : [pd_body,pd_interface,pd_implemen,pd_notobjintf];
  1207. handler : {$ifdef FPCPROCVAR}@{$endif}pd_export;
  1208. pocall : pocall_none;
  1209. pooption : [po_exports,po_public];
  1210. mutexclpocall : [pocall_internproc,pocall_inline];
  1211. mutexclpotype : [potype_constructor,potype_destructor];
  1212. mutexclpo : [po_external,po_interrupt]
  1213. ),(
  1214. idtok:_EXTERNAL;
  1215. pd_flags : [pd_implemen,pd_interface,pd_notobject,pd_notobjintf];
  1216. handler : {$ifdef FPCPROCVAR}@{$endif}pd_external;
  1217. pocall : pocall_none;
  1218. pooption : [po_external];
  1219. mutexclpocall : [pocall_internproc,pocall_inline,pocall_syscall];
  1220. mutexclpotype : [potype_constructor,potype_destructor];
  1221. mutexclpo : [po_exports,po_interrupt,po_assembler]
  1222. ),(
  1223. idtok:_FAR;
  1224. pd_flags : [pd_implemen,pd_body,pd_interface,pd_procvar,pd_notobject,pd_notobjintf];
  1225. handler : {$ifdef FPCPROCVAR}@{$endif}pd_far;
  1226. pocall : pocall_none;
  1227. pooption : [];
  1228. mutexclpocall : [pocall_internproc,pocall_inline];
  1229. mutexclpotype : [];
  1230. mutexclpo : []
  1231. ),(
  1232. idtok:_FAR16;
  1233. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobject];
  1234. handler : nil;
  1235. pocall : pocall_far16;
  1236. pooption : [];
  1237. mutexclpocall : [];
  1238. mutexclpotype : [];
  1239. mutexclpo : [po_external]
  1240. ),(
  1241. idtok:_FORWARD;
  1242. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf];
  1243. handler : {$ifdef FPCPROCVAR}@{$endif}pd_forward;
  1244. pocall : pocall_none;
  1245. pooption : [];
  1246. mutexclpocall : [pocall_internproc,pocall_inline];
  1247. mutexclpotype : [];
  1248. mutexclpo : [po_external]
  1249. ),(
  1250. idtok:_OLDFPCCALL;
  1251. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1252. handler : nil;
  1253. pocall : pocall_oldfpccall;
  1254. pooption : [];
  1255. mutexclpocall : [];
  1256. mutexclpotype : [];
  1257. mutexclpo : []
  1258. ),(
  1259. idtok:_INLINE;
  1260. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1261. handler : {$ifdef FPCPROCVAR}@{$endif}pd_inline;
  1262. pocall : pocall_inline;
  1263. pooption : [];
  1264. mutexclpocall : [];
  1265. mutexclpotype : [potype_constructor,potype_destructor];
  1266. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod]
  1267. ),(
  1268. idtok:_INTERNCONST;
  1269. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1270. handler : {$ifdef FPCPROCVAR}@{$endif}pd_intern;
  1271. pocall : pocall_none;
  1272. pooption : [po_internconst];
  1273. mutexclpocall : [];
  1274. mutexclpotype : [potype_operator];
  1275. mutexclpo : []
  1276. ),(
  1277. idtok:_INTERNPROC;
  1278. pd_flags : [pd_implemen,pd_notobject,pd_notobjintf];
  1279. handler : {$ifdef FPCPROCVAR}@{$endif}pd_intern;
  1280. pocall : pocall_internproc;
  1281. pooption : [];
  1282. mutexclpocall : [];
  1283. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1284. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_virtualmethod]
  1285. ),(
  1286. idtok:_INTERRUPT;
  1287. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1288. handler : {$ifdef FPCPROCVAR}@{$endif}pd_interrupt;
  1289. pocall : pocall_none;
  1290. pooption : [po_interrupt];
  1291. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,pocall_stdcall,
  1292. pocall_inline,pocall_pascal,pocall_far16,pocall_oldfpccall];
  1293. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1294. mutexclpo : [po_external]
  1295. ),(
  1296. idtok:_IOCHECK;
  1297. pd_flags : [pd_implemen,pd_body,pd_notobjintf];
  1298. handler : nil;
  1299. pocall : pocall_none;
  1300. pooption : [po_iocheck];
  1301. mutexclpocall : [pocall_internproc];
  1302. mutexclpotype : [];
  1303. mutexclpo : [po_external]
  1304. ),(
  1305. idtok:_MESSAGE;
  1306. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1307. handler : {$ifdef FPCPROCVAR}@{$endif}pd_message;
  1308. pocall : pocall_none;
  1309. pooption : []; { can be po_msgstr or po_msgint }
  1310. mutexclpocall : [pocall_inline,pocall_internproc];
  1311. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1312. mutexclpo : [po_interrupt,po_external]
  1313. ),(
  1314. idtok:_NEAR;
  1315. pd_flags : [pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1316. handler : {$ifdef FPCPROCVAR}@{$endif}pd_near;
  1317. pocall : pocall_none;
  1318. pooption : [];
  1319. mutexclpocall : [pocall_internproc];
  1320. mutexclpotype : [];
  1321. mutexclpo : []
  1322. ),(
  1323. idtok:_OVERLOAD;
  1324. pd_flags : [pd_implemen,pd_interface,pd_body];
  1325. handler : {$ifdef FPCPROCVAR}@{$endif}pd_overload;
  1326. pocall : pocall_none;
  1327. pooption : [po_overload];
  1328. mutexclpocall : [pocall_internproc];
  1329. mutexclpotype : [];
  1330. mutexclpo : []
  1331. ),(
  1332. idtok:_OVERRIDE;
  1333. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1334. handler : {$ifdef FPCPROCVAR}@{$endif}pd_override;
  1335. pocall : pocall_none;
  1336. pooption : [po_overridingmethod,po_virtualmethod];
  1337. mutexclpocall : [pocall_inline,pocall_internproc];
  1338. mutexclpotype : [];
  1339. mutexclpo : [po_exports,po_external,po_interrupt,po_virtualmethod]
  1340. ),(
  1341. idtok:_PASCAL;
  1342. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1343. handler : nil;
  1344. pocall : pocall_pascal;
  1345. pooption : [];
  1346. mutexclpocall : [];
  1347. mutexclpotype : [potype_constructor,potype_destructor];
  1348. mutexclpo : [po_external]
  1349. ),(
  1350. idtok:_PUBLIC;
  1351. pd_flags : [pd_implemen,pd_body,pd_notobject,pd_notobjintf];
  1352. handler : nil;
  1353. pocall : pocall_none;
  1354. pooption : [po_public];
  1355. mutexclpocall : [pocall_internproc,pocall_inline];
  1356. mutexclpotype : [];
  1357. mutexclpo : [po_external]
  1358. ),(
  1359. idtok:_REGISTER;
  1360. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1361. handler : nil;
  1362. pocall : pocall_register;
  1363. pooption : [];
  1364. mutexclpocall : [];
  1365. mutexclpotype : [potype_constructor,potype_destructor];
  1366. mutexclpo : [po_external]
  1367. ),(
  1368. idtok:_REINTRODUCE;
  1369. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1370. handler : {$ifdef FPCPROCVAR}@{$endif}pd_reintroduce;
  1371. pocall : pocall_none;
  1372. pooption : [po_reintroduce];
  1373. mutexclpocall : [pocall_inline,pocall_internproc];
  1374. mutexclpotype : [];
  1375. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod]
  1376. ),(
  1377. idtok:_SAFECALL;
  1378. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1379. handler : nil;
  1380. pocall : pocall_safecall;
  1381. pooption : [];
  1382. mutexclpocall : [];
  1383. mutexclpotype : [potype_constructor,potype_destructor];
  1384. mutexclpo : [po_external]
  1385. ),(
  1386. idtok:_SAVEREGISTERS;
  1387. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar,pd_notobjintf];
  1388. handler : nil;
  1389. pocall : pocall_none;
  1390. pooption : [po_saveregisters];
  1391. mutexclpocall : [pocall_internproc];
  1392. mutexclpotype : [potype_constructor,potype_destructor];
  1393. mutexclpo : [po_external]
  1394. ),(
  1395. idtok:_SOFTFLOAT;
  1396. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1397. handler : nil;
  1398. pocall : pocall_softfloat;
  1399. pooption : [];
  1400. mutexclpocall : [];
  1401. mutexclpotype : [potype_constructor,potype_destructor];
  1402. { it's available with po_external because the libgcc floating point routines on the arm
  1403. uses this calling convention }
  1404. mutexclpo : []
  1405. ),(
  1406. idtok:_STATIC;
  1407. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1408. handler : {$ifdef FPCPROCVAR}@{$endif}pd_static;
  1409. pocall : pocall_none;
  1410. pooption : [po_staticmethod];
  1411. mutexclpocall : [pocall_inline,pocall_internproc];
  1412. mutexclpotype : [potype_constructor,potype_destructor];
  1413. mutexclpo : [po_external,po_interrupt,po_exports]
  1414. ),(
  1415. idtok:_STDCALL;
  1416. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1417. handler : nil;
  1418. pocall : pocall_stdcall;
  1419. pooption : [];
  1420. mutexclpocall : [];
  1421. mutexclpotype : [potype_constructor,potype_destructor];
  1422. mutexclpo : [po_external]
  1423. ),(
  1424. idtok:_SYSCALL;
  1425. pd_flags : [pd_interface,pd_implemen,pd_notobject,pd_notobjintf];
  1426. handler : {$ifdef FPCPROCVAR}@{$endif}pd_syscall;
  1427. pocall : pocall_syscall;
  1428. pooption : [];
  1429. mutexclpocall : [];
  1430. mutexclpotype : [potype_constructor,potype_destructor];
  1431. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1432. ),(
  1433. idtok:_VIRTUAL;
  1434. pd_flags : [pd_interface,pd_object,pd_notobjintf];
  1435. handler : {$ifdef FPCPROCVAR}@{$endif}pd_virtual;
  1436. pocall : pocall_none;
  1437. pooption : [po_virtualmethod];
  1438. mutexclpocall : [pocall_inline,pocall_internproc];
  1439. mutexclpotype : [];
  1440. mutexclpo : [po_external,po_interrupt,po_exports,po_overridingmethod]
  1441. ),(
  1442. idtok:_CPPDECL;
  1443. pd_flags : [pd_interface,pd_implemen,pd_body,pd_procvar];
  1444. handler : nil;
  1445. pocall : pocall_cppdecl;
  1446. pooption : [];
  1447. mutexclpocall : [];
  1448. mutexclpotype : [potype_constructor,potype_destructor];
  1449. mutexclpo : [po_assembler,po_external,po_virtualmethod]
  1450. ),(
  1451. idtok:_VARARGS;
  1452. pd_flags : [pd_interface,pd_implemen,pd_procvar];
  1453. handler : nil;
  1454. pocall : pocall_none;
  1455. pooption : [po_varargs];
  1456. mutexclpocall : [pocall_internproc,pocall_stdcall,pocall_register,
  1457. pocall_inline,pocall_far16,pocall_oldfpccall];
  1458. mutexclpotype : [];
  1459. mutexclpo : [po_assembler,po_interrupt]
  1460. ),(
  1461. idtok:_COMPILERPROC;
  1462. pd_flags : [pd_interface,pd_implemen,pd_body,pd_notobjintf];
  1463. handler : nil;
  1464. pocall : pocall_compilerproc;
  1465. pooption : [];
  1466. mutexclpocall : [];
  1467. mutexclpotype : [potype_constructor,potype_destructor];
  1468. mutexclpo : [po_interrupt]
  1469. )
  1470. );
  1471. function is_proc_directive(tok:ttoken;isprocvar:boolean):boolean;
  1472. var
  1473. i : longint;
  1474. begin
  1475. is_proc_directive:=false;
  1476. for i:=1 to num_proc_directives do
  1477. if proc_direcdata[i].idtok=idtoken then
  1478. begin
  1479. if (not isprocvar) or
  1480. (pd_procvar in proc_direcdata[i].pd_flags) then
  1481. is_proc_directive:=true;
  1482. exit;
  1483. end;
  1484. end;
  1485. function parse_proc_direc(pd:tabstractprocdef;var pdflags:tpdflags):boolean;
  1486. {
  1487. Parse the procedure directive, returns true if a correct directive is found
  1488. }
  1489. var
  1490. p : longint;
  1491. found : boolean;
  1492. name : stringid;
  1493. begin
  1494. parse_proc_direc:=false;
  1495. name:=tokeninfo^[idtoken].str;
  1496. found:=false;
  1497. { Hint directive? Then exit immediatly }
  1498. if (m_hintdirective in aktmodeswitches) then
  1499. begin
  1500. case idtoken of
  1501. _LIBRARY,
  1502. _PLATFORM,
  1503. _UNIMPLEMENTED,
  1504. _DEPRECATED :
  1505. exit;
  1506. end;
  1507. end;
  1508. { retrieve data for directive if found }
  1509. for p:=1 to num_proc_directives do
  1510. if proc_direcdata[p].idtok=idtoken then
  1511. begin
  1512. found:=true;
  1513. break;
  1514. end;
  1515. { Check if the procedure directive is known }
  1516. if not found then
  1517. begin
  1518. { parsing a procvar type the name can be any
  1519. next variable !! }
  1520. if (pdflags * [pd_procvar,pd_object])=[] then
  1521. Message1(parser_w_unknown_proc_directive_ignored,name);
  1522. exit;
  1523. end;
  1524. { static needs a special treatment }
  1525. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1526. exit;
  1527. { Conflicts between directives ? }
  1528. if (pd.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1529. (pd.proccalloption in proc_direcdata[p].mutexclpocall) or
  1530. ((pd.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1531. begin
  1532. Message1(parser_e_proc_dir_conflict,name);
  1533. exit;
  1534. end;
  1535. { set calling convention }
  1536. if proc_direcdata[p].pocall<>pocall_none then
  1537. begin
  1538. if (po_hascallingconvention in pd.procoptions) then
  1539. begin
  1540. Message2(parser_w_proc_overriding_calling,
  1541. proccalloptionStr[pd.proccalloption],
  1542. proccalloptionStr[proc_direcdata[p].pocall]);
  1543. end;
  1544. { check if the target processor supports this calling convention }
  1545. if not(proc_direcdata[p].pocall in supported_calling_conventions) then
  1546. begin
  1547. Message1(parser_e_illegal_calling_convention,proccalloptionStr[proc_direcdata[p].pocall]);
  1548. { recover }
  1549. proc_direcdata[p].pocall:=pocall_stdcall;
  1550. end;
  1551. pd.proccalloption:=proc_direcdata[p].pocall;
  1552. include(pd.procoptions,po_hascallingconvention);
  1553. end;
  1554. { check if method and directive not for object, like public.
  1555. This needs to be checked also for procvars }
  1556. if (pd_notobject in proc_direcdata[p].pd_flags) and
  1557. (pd.owner.symtabletype=objectsymtable) then
  1558. exit;
  1559. if pd.deftype=procdef then
  1560. begin
  1561. { Check if the directive is only for objects }
  1562. if (pd_object in proc_direcdata[p].pd_flags) and
  1563. not assigned(tprocdef(pd)._class) then
  1564. exit;
  1565. { check if method and directive not for interface }
  1566. if (pd_notobjintf in proc_direcdata[p].pd_flags) and
  1567. is_interface(tprocdef(pd)._class) then
  1568. exit;
  1569. end;
  1570. { consume directive, and turn flag on }
  1571. consume(token);
  1572. parse_proc_direc:=true;
  1573. { Check the pd_flags if the directive should be allowed }
  1574. if (pd_interface in pdflags) and
  1575. not(pd_interface in proc_direcdata[p].pd_flags) then
  1576. begin
  1577. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1578. exit;
  1579. end;
  1580. if (pd_implemen in pdflags) and
  1581. not(pd_implemen in proc_direcdata[p].pd_flags) then
  1582. begin
  1583. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1584. exit;
  1585. end;
  1586. if (pd_procvar in pdflags) and
  1587. not(pd_procvar in proc_direcdata[p].pd_flags) then
  1588. begin
  1589. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1590. exit;
  1591. end;
  1592. { Return the new pd_flags }
  1593. if not(pd_body in proc_direcdata[p].pd_flags) then
  1594. exclude(pdflags,pd_body);
  1595. { Add the correct flag }
  1596. pd.procoptions:=pd.procoptions+proc_direcdata[p].pooption;
  1597. { Call the handler }
  1598. if pointer({$ifndef FPCPROCVAR}@{$endif}proc_direcdata[p].handler)<>nil then
  1599. proc_direcdata[p].handler(pd);
  1600. end;
  1601. procedure handle_calling_convention(pd:tabstractprocdef);
  1602. begin
  1603. { set the default calling convention if none provided }
  1604. if not(po_hascallingconvention in pd.procoptions) then
  1605. pd.proccalloption:=aktdefproccall
  1606. else
  1607. begin
  1608. if pd.proccalloption=pocall_none then
  1609. internalerror(200309081);
  1610. end;
  1611. { handle proccall specific settings }
  1612. case pd.proccalloption of
  1613. pocall_cdecl :
  1614. begin
  1615. { set mangledname }
  1616. if (pd.deftype=procdef) then
  1617. begin
  1618. if not tprocdef(pd).has_mangledname then
  1619. begin
  1620. if assigned(tprocdef(pd)._class) then
  1621. tprocdef(pd).setmangledname(target_info.Cprefix+tprocdef(pd)._class.objrealname^+'_'+tprocdef(pd).procsym.realname)
  1622. else
  1623. tprocdef(pd).setmangledname(target_info.Cprefix+tprocdef(pd).procsym.realname);
  1624. end;
  1625. { check C cdecl para types }
  1626. pd.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_c_para,nil);
  1627. end;
  1628. end;
  1629. pocall_cppdecl :
  1630. begin
  1631. { set mangledname }
  1632. if (pd.deftype=procdef) then
  1633. begin
  1634. if not tprocdef(pd).has_mangledname then
  1635. tprocdef(pd).setmangledname(target_info.Cprefix+tprocdef(pd).cplusplusmangledname);
  1636. { check C cdecl para types }
  1637. pd.parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}check_c_para,nil);
  1638. end;
  1639. end;
  1640. pocall_compilerproc :
  1641. begin
  1642. if (pd.deftype<>procdef) then
  1643. internalerror(200110232);
  1644. if (target_info.system<>system_i386_watcom) then
  1645. tprocdef(pd).setmangledname(lower(tprocdef(pd).procsym.name));
  1646. end;
  1647. pocall_far16 :
  1648. begin
  1649. { Temporary stub, must be rewritten to support OS/2 far16 }
  1650. Message1(parser_w_proc_directive_ignored,'FAR16');
  1651. end;
  1652. pocall_inline :
  1653. begin
  1654. if not(cs_support_inline in aktmoduleswitches) then
  1655. begin
  1656. Message(parser_e_proc_inline_not_supported);
  1657. pd.proccalloption:=pocall_default;
  1658. end;
  1659. end;
  1660. end;
  1661. { For varargs directive also cdecl and external must be defined }
  1662. if (po_varargs in pd.procoptions) then
  1663. begin
  1664. { check first for external in the interface, if available there
  1665. then the cdecl must also be there since there is no implementation
  1666. available to contain it }
  1667. if parse_only then
  1668. begin
  1669. { if external is available, then cdecl must also be available,
  1670. procvars don't need external }
  1671. if not((po_external in pd.procoptions) or
  1672. (pd.deftype=procvardef)) and
  1673. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1674. Message(parser_e_varargs_need_cdecl_and_external);
  1675. end
  1676. else
  1677. begin
  1678. { both must be defined now }
  1679. if not((po_external in pd.procoptions) or
  1680. (pd.deftype=procvardef)) or
  1681. not(pd.proccalloption in [pocall_cdecl,pocall_cppdecl]) then
  1682. Message(parser_e_varargs_need_cdecl_and_external);
  1683. end;
  1684. end;
  1685. { add mangledname to external list }
  1686. if (pd.deftype=procdef) and
  1687. (po_external in pd.procoptions) and
  1688. target_info.DllScanSupported then
  1689. current_module.externals.insert(tExternalsItem.create(tprocdef(pd).mangledname));
  1690. end;
  1691. procedure calc_parast(pd:tabstractprocdef);
  1692. var
  1693. currpara : tparaitem;
  1694. begin
  1695. { insert hidden high parameters }
  1696. insert_hidden_para(pd);
  1697. { insert hidden self parameter }
  1698. insert_self_and_vmt_para(pd);
  1699. { insert funcret parameter if required }
  1700. insert_funcret_para(pd);
  1701. { insert parentfp parameter if required }
  1702. insert_parentfp_para(pd);
  1703. currpara:=tparaitem(pd.para.first);
  1704. while assigned(currpara) do
  1705. begin
  1706. if not(assigned(currpara.parasym) and (currpara.parasym.typ=varsym)) then
  1707. internalerror(200304232);
  1708. { connect parasym to paraitem }
  1709. tvarsym(currpara.parasym).paraitem:=currpara;
  1710. { We need a local copy for a value parameter when only the
  1711. address is pushed. Open arrays and Array of Const are
  1712. an exception because they are allocated at runtime and the
  1713. address that is pushed is patched }
  1714. if (currpara.paratyp=vs_value) and
  1715. paramanager.push_addr_param(currpara.paratyp,currpara.paratype.def,pd.proccalloption) and
  1716. not(is_open_array(currpara.paratype.def) or
  1717. is_array_of_const(currpara.paratype.def)) then
  1718. include(tvarsym(currpara.parasym).varoptions,vo_has_local_copy);
  1719. currpara:=tparaitem(currpara.next);
  1720. end;
  1721. end;
  1722. procedure parse_proc_directives(pd:tabstractprocdef;var pdflags:tpdflags);
  1723. {
  1724. Parse the procedure directives. It does not matter if procedure directives
  1725. are written using ;procdir; or ['procdir'] syntax.
  1726. }
  1727. var
  1728. res : boolean;
  1729. begin
  1730. while token in [_ID,_LECKKLAMMER] do
  1731. begin
  1732. if try_to_consume(_LECKKLAMMER) then
  1733. begin
  1734. repeat
  1735. parse_proc_direc(pd,pdflags);
  1736. until not try_to_consume(_COMMA);
  1737. consume(_RECKKLAMMER);
  1738. { we always expect at least '[];' }
  1739. res:=true;
  1740. end
  1741. else
  1742. begin
  1743. res:=parse_proc_direc(pd,pdflags);
  1744. end;
  1745. { A procedure directive normally followed by a semicolon, but in
  1746. a const section or reading a type we should stop when _EQUAL is found,
  1747. because a constant/default value follows }
  1748. if res then
  1749. begin
  1750. if (block_type in [bt_const,bt_type]) and
  1751. (token=_EQUAL) then
  1752. break;
  1753. { support procedure proc;stdcall export; }
  1754. if not(is_proc_directive(token,(pd.deftype=procvardef))) then
  1755. consume(_SEMICOLON);
  1756. end
  1757. else
  1758. break;
  1759. end;
  1760. end;
  1761. procedure parse_var_proc_directives(sym:tsym);
  1762. var
  1763. pdflags : tpdflags;
  1764. pd : tabstractprocdef;
  1765. begin
  1766. pdflags:=[pd_procvar];
  1767. pd:=nil;
  1768. case sym.typ of
  1769. varsym :
  1770. pd:=tabstractprocdef(tvarsym(sym).vartype.def);
  1771. typedconstsym :
  1772. pd:=tabstractprocdef(ttypedconstsym(sym).typedconsttype.def);
  1773. typesym :
  1774. pd:=tabstractprocdef(ttypesym(sym).restype.def);
  1775. else
  1776. internalerror(2003042617);
  1777. end;
  1778. if pd.deftype<>procvardef then
  1779. internalerror(2003042618);
  1780. { names should never be used anyway }
  1781. parse_proc_directives(pd,pdflags);
  1782. end;
  1783. procedure parse_object_proc_directives(pd:tabstractprocdef);
  1784. var
  1785. pdflags : tpdflags;
  1786. begin
  1787. pdflags:=[pd_object];
  1788. parse_proc_directives(pd,pdflags);
  1789. end;
  1790. function proc_add_definition(var pd:tprocdef):boolean;
  1791. {
  1792. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  1793. forwarddef is found and reused it returns true
  1794. }
  1795. var
  1796. hd : tprocdef;
  1797. ad,fd : tsym;
  1798. s1,s2 : stringid;
  1799. i : cardinal;
  1800. forwardfound : boolean;
  1801. po_comp : tprocoptions;
  1802. aprocsym : tprocsym;
  1803. begin
  1804. forwardfound:=false;
  1805. aprocsym:=tprocsym(pd.procsym);
  1806. { check overloaded functions if the same function already exists }
  1807. for i:=1 to aprocsym.procdef_count do
  1808. begin
  1809. hd:=aprocsym.procdef[i];
  1810. { Skip overloaded definitions that are declared in other
  1811. units }
  1812. if hd.procsym<>aprocsym then
  1813. continue;
  1814. { check the parameters, for delphi/tp it is possible to
  1815. leave the parameters away in the implementation (forwarddef=false).
  1816. But for an overload declared function this is not allowed }
  1817. if { check if empty implementation arguments match is allowed }
  1818. (
  1819. not(m_repeat_forward in aktmodeswitches) and
  1820. not(pd.forwarddef) and
  1821. (pd.maxparacount=0) and
  1822. not(po_overload in hd.procoptions)
  1823. ) or
  1824. { check arguments }
  1825. (
  1826. (compare_paras(pd.para,hd.para,cp_none,[cpo_comparedefaultvalue])>=te_equal) and
  1827. { for operators equal_paras is not enough !! }
  1828. ((pd.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  1829. equal_defs(hd.rettype.def,pd.rettype.def))
  1830. ) then
  1831. begin
  1832. { Check if we've found the forwarddef, if found then
  1833. we need to update the forward def with the current
  1834. implementation settings }
  1835. if hd.forwarddef then
  1836. begin
  1837. forwardfound:=true;
  1838. { Check if the procedure type and return type are correct,
  1839. also the parameters must match also with the type }
  1840. if (hd.proctypeoption<>pd.proctypeoption) or
  1841. (
  1842. (m_repeat_forward in aktmodeswitches) and
  1843. (not((pd.maxparacount=0) or
  1844. (compare_paras(pd.para,hd.para,cp_all,[cpo_comparedefaultvalue])>=te_equal)))
  1845. ) or
  1846. (
  1847. ((m_repeat_forward in aktmodeswitches) or
  1848. not(is_void(pd.rettype.def))) and
  1849. (not equal_defs(hd.rettype.def,pd.rettype.def))) then
  1850. begin
  1851. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  1852. pd.fullprocname(false));
  1853. aprocsym.write_parameter_lists(pd);
  1854. break;
  1855. end;
  1856. { Check if both are declared forward }
  1857. if hd.forwarddef and pd.forwarddef then
  1858. begin
  1859. MessagePos1(pd.fileinfo,parser_e_function_already_declared_public_forward,
  1860. pd.fullprocname(false));
  1861. end;
  1862. { internconst or internproc only need to be defined once }
  1863. if (hd.proccalloption=pocall_internproc) then
  1864. pd.proccalloption:=hd.proccalloption
  1865. else
  1866. if (pd.proccalloption=pocall_internproc) then
  1867. hd.proccalloption:=pd.proccalloption;
  1868. if (po_internconst in hd.procoptions) then
  1869. include(pd.procoptions,po_internconst)
  1870. else if (po_internconst in pd.procoptions) then
  1871. include(hd.procoptions,po_internconst);
  1872. { Check calling convention }
  1873. if (hd.proccalloption<>pd.proccalloption) then
  1874. begin
  1875. { In delphi it is possible to specify the calling
  1876. convention in the interface or implementation if
  1877. there was no convention specified in the other
  1878. part }
  1879. if (m_delphi in aktmodeswitches) then
  1880. begin
  1881. if not(po_hascallingconvention in pd.procoptions) then
  1882. pd.proccalloption:=hd.proccalloption
  1883. else
  1884. if not(po_hascallingconvention in hd.procoptions) then
  1885. hd.proccalloption:=pd.proccalloption
  1886. else
  1887. begin
  1888. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  1889. aprocsym.write_parameter_lists(pd);
  1890. { restore interface settings }
  1891. pd.proccalloption:=hd.proccalloption;
  1892. end;
  1893. end
  1894. else
  1895. begin
  1896. MessagePos(pd.fileinfo,parser_e_call_convention_dont_match_forward);
  1897. aprocsym.write_parameter_lists(pd);
  1898. { restore interface settings }
  1899. pd.proccalloption:=hd.proccalloption;
  1900. end;
  1901. end;
  1902. { Check procedure options, Delphi requires that class is
  1903. repeated in the implementation for class methods }
  1904. if (m_fpc in aktmodeswitches) then
  1905. po_comp:=[po_varargs,po_methodpointer,po_interrupt]
  1906. else
  1907. po_comp:=[po_classmethod,po_methodpointer];
  1908. if ((po_comp * hd.procoptions)<>(po_comp * pd.procoptions)) then
  1909. begin
  1910. MessagePos1(pd.fileinfo,parser_e_header_dont_match_forward,
  1911. pd.fullprocname(false));
  1912. aprocsym.write_parameter_lists(pd);
  1913. { This error is non-fatal, we can recover }
  1914. end;
  1915. { Check manglednames }
  1916. if (m_repeat_forward in aktmodeswitches) or
  1917. (pd.minparacount>0) then
  1918. begin
  1919. { If mangled names are equal then they have the same amount of arguments }
  1920. { We can check the names of the arguments }
  1921. { both symtables are in the same order from left to right }
  1922. ad:=tsym(hd.parast.symindex.first);
  1923. fd:=tsym(pd.parast.symindex.first);
  1924. repeat
  1925. { skip default parameter constsyms }
  1926. while assigned(ad) and (ad.typ<>varsym) do
  1927. ad:=tsym(ad.indexnext);
  1928. while assigned(fd) and (fd.typ<>varsym) do
  1929. fd:=tsym(fd.indexnext);
  1930. { stop when one of the two lists is at the end }
  1931. if not assigned(ad) or not assigned(fd) then
  1932. break;
  1933. { retrieve names, remove reg for register parameters }
  1934. s1:=ad.name;
  1935. s2:=fd.name;
  1936. { compare names }
  1937. if (s1<>s2) then
  1938. begin
  1939. MessagePos3(pd.fileinfo,parser_e_header_different_var_names,
  1940. aprocsym.name,s1,s2);
  1941. break;
  1942. end;
  1943. ad:=tsym(ad.indexnext);
  1944. fd:=tsym(fd.indexnext);
  1945. until false;
  1946. if assigned(ad) xor assigned(fd) then
  1947. internalerror(200204178);
  1948. end;
  1949. { Everything is checked, now we can update the forward declaration
  1950. with the new data from the implementation }
  1951. hd.forwarddef:=pd.forwarddef;
  1952. hd.hasforward:=true;
  1953. hd.procoptions:=hd.procoptions+pd.procoptions;
  1954. if hd.extnumber=65535 then
  1955. hd.extnumber:=pd.extnumber;
  1956. while not pd.aliasnames.empty do
  1957. hd.aliasnames.insert(pd.aliasnames.getfirst);
  1958. { update fileinfo so position references the implementation,
  1959. also update funcretsym if it is already generated }
  1960. hd.fileinfo:=pd.fileinfo;
  1961. if assigned(hd.funcretsym) then
  1962. hd.funcretsym.fileinfo:=pd.fileinfo;
  1963. { update mangledname if the implementation has a fixed mangledname set }
  1964. if pd.has_mangledname then
  1965. begin
  1966. { rename also asmsymbol first, because the name can already be used }
  1967. objectlibrary.renameasmsymbol(hd.mangledname,pd.mangledname);
  1968. hd.setmangledname(pd.mangledname);
  1969. end;
  1970. { for compilerproc defines we need to rename and update the
  1971. symbolname to lowercase }
  1972. if (pd.proccalloption=pocall_compilerproc) then
  1973. begin
  1974. { rename to lowercase so users can't access it }
  1975. aprocsym.owner.rename(aprocsym.name,lower(aprocsym.name));
  1976. { also update the realname that is stored in the ppu }
  1977. stringdispose(aprocsym._realname);
  1978. aprocsym._realname:=stringdup('$'+aprocsym.name);
  1979. { the mangeled name is already changed by the pd_compilerproc }
  1980. { handler. It must be done immediately because if we have a }
  1981. { call to a compilerproc before it's implementation is }
  1982. { encountered, it must already use the new mangled name (JM) }
  1983. end;
  1984. { the procdef will be released by the symtable, we release
  1985. at least the parast }
  1986. pd.releasemem;
  1987. pd:=hd;
  1988. end
  1989. else
  1990. begin
  1991. { abstract methods aren't forward defined, but this }
  1992. { needs another error message }
  1993. if (po_abstractmethod in hd.procoptions) then
  1994. MessagePos(pd.fileinfo,parser_e_abstract_no_definition)
  1995. else
  1996. MessagePos(pd.fileinfo,parser_e_overloaded_have_same_parameters);
  1997. end;
  1998. { we found one proc with the same arguments, there are no others
  1999. so we can stop }
  2000. break;
  2001. end;
  2002. { check for allowing overload directive }
  2003. if not(m_fpc in aktmodeswitches) then
  2004. begin
  2005. { overload directive turns on overloading }
  2006. if ((po_overload in pd.procoptions) or
  2007. (po_overload in hd.procoptions)) then
  2008. begin
  2009. { check if all procs have overloading, but not if the proc is a method or
  2010. already declared forward, then the check is already done }
  2011. if not(hd.hasforward or
  2012. assigned(pd._class) or
  2013. (pd.forwarddef<>hd.forwarddef) or
  2014. ((po_overload in pd.procoptions) and
  2015. (po_overload in hd.procoptions))) then
  2016. begin
  2017. MessagePos1(pd.fileinfo,parser_e_no_overload_for_all_procs,aprocsym.realname);
  2018. break;
  2019. end;
  2020. end
  2021. else
  2022. begin
  2023. if not(hd.forwarddef) then
  2024. begin
  2025. MessagePos(pd.fileinfo,parser_e_procedure_overloading_is_off);
  2026. break;
  2027. end;
  2028. end;
  2029. end; { equal arguments }
  2030. end;
  2031. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  2032. list }
  2033. if not forwardfound then
  2034. begin
  2035. aprocsym.addprocdef(pd);
  2036. { add overloadnumber for unique naming, the overloadcount is
  2037. counted per module and 0 for the first procedure }
  2038. pd.overloadnumber:=aprocsym.overloadcount;
  2039. inc(aprocsym.overloadcount);
  2040. end;
  2041. proc_add_definition:=forwardfound;
  2042. end;
  2043. end.
  2044. {
  2045. $Log$
  2046. Revision 1.168 2004-04-28 15:19:03 florian
  2047. + syscall directive support for MorphOS added
  2048. Revision 1.167 2004/04/28 00:20:43 karoly
  2049. * fixed locationstr having nonsense values in some cases
  2050. Revision 1.166 2004/04/19 02:12:18 karoly
  2051. * quick fix for PowerPC/MorphOS location support
  2052. Revision 1.165 2004/04/18 15:22:24 florian
  2053. + location support for arguments, currently PowerPC/MorphOS only
  2054. Revision 1.164 2004/02/26 16:13:25 peter
  2055. * fix crash when method is not declared in object declaration
  2056. * fix parsing of mapped interface functions
  2057. Revision 1.163 2004/02/20 21:54:47 peter
  2058. * use sp_internal flag to silence unused internal variable
  2059. Revision 1.162 2004/02/13 15:41:24 peter
  2060. * overload directive checking for methods is now done
  2061. when the vmt is generated
  2062. Revision 1.161 2004/02/05 14:13:53 daniel
  2063. * Tvarsym.highvarsym removed
  2064. Revision 1.160 2004/02/04 22:54:57 daniel
  2065. * Tvarsym.highvarsym commented out (unused by compiler, purpose unknown)
  2066. Revision 1.159 2004/02/04 22:15:15 daniel
  2067. * Rtti generation moved to ncgutil
  2068. * Assmtai usage of symsym removed
  2069. * operator overloading cleanup up
  2070. Revision 1.158 2004/02/03 22:32:54 peter
  2071. * renamed xNNbittype to xNNinttype
  2072. * renamed registers32 to registersint
  2073. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  2074. Revision 1.157 2004/01/31 17:45:17 peter
  2075. * Change several $ifdef i386 to x86
  2076. * Change several OS_32 to OS_INT/OS_ADDR
  2077. Revision 1.156 2004/01/21 14:22:00 florian
  2078. + reintroduce implemented
  2079. Revision 1.155 2003/11/23 17:05:15 peter
  2080. * register calling is left-right
  2081. * parameter ordering
  2082. * left-right calling inserts result parameter last
  2083. Revision 1.154 2003/11/12 15:49:06 peter
  2084. * virtual conflicts with override
  2085. Revision 1.153 2003/11/10 19:09:29 peter
  2086. * procvar default value support
  2087. Revision 1.152 2003/11/07 15:58:32 florian
  2088. * Florian's culmutative nr. 1; contains:
  2089. - invalid calling conventions for a certain cpu are rejected
  2090. - arm softfloat calling conventions
  2091. - -Sp for cpu dependend code generation
  2092. - several arm fixes
  2093. - remaining code for value open array paras on heap
  2094. Revision 1.151 2003/11/03 17:47:30 peter
  2095. * insert framepointer as voidpointer instead of returntype
  2096. Revision 1.150 2003/10/30 16:23:13 peter
  2097. * don't search for overloads in parents for constructors
  2098. Revision 1.149 2003/10/28 15:36:01 peter
  2099. * absolute to object field supported, fixes tb0458
  2100. Revision 1.148 2003/10/07 21:14:33 peter
  2101. * compare_paras() has a parameter to ignore hidden parameters
  2102. * cross unit overload searching ignores hidden parameters when
  2103. comparing parameter lists. Now function(string):string is
  2104. not overriden with procedure(string) which has the same visible
  2105. parameter list
  2106. Revision 1.147 2003/10/07 20:52:54 peter
  2107. * procvar varargs fixed
  2108. Revision 1.146 2003/10/05 21:21:52 peter
  2109. * c style array of const generates callparanodes
  2110. * varargs paraloc fixes
  2111. Revision 1.145 2003/10/05 11:10:52 peter
  2112. * temporary fix for compilerprocs on watcom
  2113. Revision 1.144 2003/10/03 22:00:33 peter
  2114. * parameter alignment fixes
  2115. Revision 1.143 2003/10/02 21:13:09 peter
  2116. * procvar directive parsing fixes
  2117. Revision 1.142 2003/10/01 19:05:33 peter
  2118. * searchsym_type to search for type definitions. It ignores
  2119. records,objects and parameters
  2120. Revision 1.141 2003/10/01 18:28:55 peter
  2121. * don't look in objectsymtable when parsing the function return type
  2122. Revision 1.140 2003/10/01 16:49:05 florian
  2123. * para items are now reversed for pascal calling conventions
  2124. Revision 1.139 2003/09/28 21:44:55 peter
  2125. * fix check that filedef needs var para
  2126. Revision 1.138 2003/09/28 17:55:04 peter
  2127. * parent framepointer changed to hidden parameter
  2128. * tloadparentfpnode added
  2129. Revision 1.137 2003/09/25 21:24:09 peter
  2130. * don't include vo_has_local_copy for open array/array of const
  2131. Revision 1.136 2003/09/23 20:36:47 peter
  2132. * remove obsolete code
  2133. Revision 1.135 2003/09/23 17:56:05 peter
  2134. * locals and paras are allocated in the code generation
  2135. * tvarsym.localloc contains the location of para/local when
  2136. generating code for the current procedure
  2137. Revision 1.134 2003/09/16 16:17:01 peter
  2138. * varspez in calls to push_addr_param
  2139. Revision 1.133 2003/09/09 21:03:17 peter
  2140. * basics for x86 register calling
  2141. Revision 1.132 2003/09/09 15:54:10 peter
  2142. * calling convention fix
  2143. Revision 1.131 2003/09/07 22:09:35 peter
  2144. * preparations for different default calling conventions
  2145. * various RA fixes
  2146. Revision 1.130 2003/09/03 11:18:37 florian
  2147. * fixed arm concatcopy
  2148. + arm support in the common compiler sources added
  2149. * moved some generic cg code around
  2150. + tfputype added
  2151. * ...
  2152. Revision 1.129 2003/07/02 22:18:04 peter
  2153. * paraloc splitted in callerparaloc,calleeparaloc
  2154. * sparc calling convention updates
  2155. Revision 1.128 2003/06/13 21:19:31 peter
  2156. * current_procdef removed, use current_procinfo.procdef instead
  2157. Revision 1.127 2003/06/05 20:04:43 peter
  2158. * set po_public also when parsing the object declaration
  2159. Revision 1.126 2003/06/02 21:42:05 jonas
  2160. * function results can now also be regvars
  2161. - removed tprocinfo.return_offset, never use it again since it's invalid
  2162. if the result is a regvar
  2163. Revision 1.125 2003/05/22 21:31:35 peter
  2164. * defer codegeneration for nested procedures
  2165. Revision 1.124 2003/05/15 18:58:53 peter
  2166. * removed selfpointer_offset, vmtpointer_offset
  2167. * tvarsym.adjusted_address
  2168. * address in localsymtable is now in the real direction
  2169. * removed some obsolete globals
  2170. Revision 1.123 2003/05/13 15:18:49 peter
  2171. * fixed various crashes
  2172. Revision 1.122 2003/05/09 17:47:03 peter
  2173. * self moved to hidden parameter
  2174. * removed hdisposen,hnewn,selfn
  2175. Revision 1.121 2003/05/05 14:53:16 peter
  2176. * vs_hidden replaced by is_hidden boolean
  2177. Revision 1.120 2003/04/30 09:42:42 florian
  2178. + first changes to make self a hidden parameter
  2179. Revision 1.119 2003/04/27 11:21:33 peter
  2180. * aktprocdef renamed to current_procinfo.procdef
  2181. * procinfo renamed to current_procinfo
  2182. * procinfo will now be stored in current_module so it can be
  2183. cleaned up properly
  2184. * gen_main_procsym changed to create_main_proc and release_main_proc
  2185. to also generate a tprocinfo structure
  2186. * fixed unit implicit initfinal
  2187. Revision 1.118 2003/04/27 07:29:50 peter
  2188. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  2189. a new procdef declaration
  2190. * aktprocsym removed
  2191. * lexlevel removed, use symtable.symtablelevel instead
  2192. * implicit init/final code uses the normal genentry/genexit
  2193. * funcret state checking updated for new funcret handling
  2194. Revision 1.117 2003/04/26 00:33:07 peter
  2195. * vo_is_result flag added for the special RESULT symbol
  2196. Revision 1.116 2003/04/25 20:59:33 peter
  2197. * removed funcretn,funcretsym, function result is now in varsym
  2198. and aliases for result and function name are added using absolutesym
  2199. * vs_hidden parameter for funcret passed in parameter
  2200. * vs_hidden fixes
  2201. * writenode changed to printnode and released from extdebug
  2202. * -vp option added to generate a tree.log with the nodetree
  2203. * nicer printnode for statements, callnode
  2204. Revision 1.115 2003/04/24 13:03:01 florian
  2205. * comp is now written with its bit pattern to the ppu instead as an extended
  2206. Revision 1.114 2003/04/23 13:12:26 peter
  2207. * fix po_comp setting for fpc mode
  2208. Revision 1.113 2003/04/23 10:12:51 peter
  2209. * don't check po_varargs for delphi
  2210. Revision 1.112 2003/04/22 13:47:08 peter
  2211. * fixed C style array of const
  2212. * fixed C array passing
  2213. * fixed left to right with high parameters
  2214. Revision 1.111 2003/04/10 17:57:53 peter
  2215. * vs_hidden released
  2216. Revision 1.110 2003/03/28 19:16:56 peter
  2217. * generic constructor working for i386
  2218. * remove fixed self register
  2219. * esi added as address register for i386
  2220. Revision 1.109 2003/03/23 23:21:42 hajny
  2221. + emx target added
  2222. Revision 1.108 2003/03/19 17:34:04 peter
  2223. * only allow class [procedure|function]
  2224. Revision 1.107 2003/03/17 18:56:02 peter
  2225. * fix crash with duplicate id
  2226. Revision 1.106 2003/03/17 15:54:22 peter
  2227. * store symoptions also for procdef
  2228. * check symoptions (private,public) when calculating possible
  2229. overload candidates
  2230. Revision 1.105 2003/01/15 20:02:28 carl
  2231. * fix highname problem
  2232. Revision 1.104 2003/01/12 15:42:23 peter
  2233. * m68k pathexist update from 1.0.x
  2234. * palmos res update from 1.0.x
  2235. Revision 1.103 2003/01/07 19:16:38 peter
  2236. * removed some duplicate code when creating aktprocsym
  2237. Revision 1.102 2003/01/05 18:17:45 peter
  2238. * more conflicts for constructor/destructor types
  2239. Revision 1.100 2003/01/02 19:49:00 peter
  2240. * update self parameter only for methodpointer and methods
  2241. Revision 1.99 2003/01/01 22:51:03 peter
  2242. * high value insertion changed so it works also when 2 parameters
  2243. are passed
  2244. Revision 1.98 2003/01/01 14:35:33 peter
  2245. * don't check for export directive repeat
  2246. Revision 1.97 2002/12/29 18:16:06 peter
  2247. * delphi allows setting calling convention in interface or
  2248. implementation
  2249. Revision 1.96 2002/12/29 14:55:44 peter
  2250. * fix static method check
  2251. * don't require class for class methods in the implementation for
  2252. non delphi modes
  2253. Revision 1.95 2002/12/27 15:25:14 peter
  2254. * check procoptions when a forward is found
  2255. * exclude some call directives for constructor/destructor
  2256. Revision 1.94 2002/12/25 01:26:56 peter
  2257. * duplicate procsym-unitsym fix
  2258. Revision 1.93 2002/12/24 21:21:06 peter
  2259. * remove code that skipped the _ prefix for win32 imports
  2260. Revision 1.92 2002/12/23 21:24:22 peter
  2261. * fix wrong internalerror when var names were different
  2262. Revision 1.91 2002/12/23 20:58:52 peter
  2263. * cdecl array fix, hack to change it to vs_var is not needed
  2264. Revision 1.90 2002/12/17 22:19:33 peter
  2265. * fixed pushing of records>8 bytes with stdcall
  2266. * simplified hightree loading
  2267. Revision 1.89 2002/12/15 21:07:30 peter
  2268. * don't allow external in object declarations
  2269. Revision 1.88 2002/12/15 19:34:31 florian
  2270. + some front end stuff for vs_hidden added
  2271. Revision 1.87 2002/12/07 14:27:07 carl
  2272. * 3% memory optimization
  2273. * changed some types
  2274. + added type checking with different size for call node and for
  2275. parameters
  2276. Revision 1.86 2002/12/06 17:51:10 peter
  2277. * merged cdecl and array fixes
  2278. Revision 1.85 2002/12/01 22:06:14 carl
  2279. * cleanup of error messages
  2280. Revision 1.84 2002/11/29 22:31:19 carl
  2281. + unimplemented hint directive added
  2282. * hint directive parsing implemented
  2283. * warning on these directives
  2284. Revision 1.83 2002/11/27 02:35:28 peter
  2285. * fixed typo in method comparing
  2286. Revision 1.82 2002/11/25 17:43:21 peter
  2287. * splitted defbase in defutil,symutil,defcmp
  2288. * merged isconvertable and is_equal into compare_defs(_ext)
  2289. * made operator search faster by walking the list only once
  2290. Revision 1.81 2002/11/18 17:31:58 peter
  2291. * pass proccalloption to ret_in_xxx and push_xxx functions
  2292. Revision 1.80 2002/11/17 16:31:56 carl
  2293. * memory optimization (3-4%) : cleanup of tai fields,
  2294. cleanup of tdef and tsym fields.
  2295. * make it work for m68k
  2296. Revision 1.79 2002/11/16 14:20:50 peter
  2297. * fix infinite loop in pd_inline
  2298. Revision 1.78 2002/11/15 01:58:53 peter
  2299. * merged changes from 1.0.7 up to 04-11
  2300. - -V option for generating bug report tracing
  2301. - more tracing for option parsing
  2302. - errors for cdecl and high()
  2303. - win32 import stabs
  2304. - win32 records<=8 are returned in eax:edx (turned off by default)
  2305. - heaptrc update
  2306. - more info for temp management in .s file with EXTDEBUG
  2307. Revision 1.77 2002/10/06 15:09:12 peter
  2308. * variant:=nil supported
  2309. Revision 1.76 2002/09/27 21:13:29 carl
  2310. * low-highval always checked if limit ober 2GB is reached (to avoid overflow)
  2311. Revision 1.75 2002/09/16 14:11:13 peter
  2312. * add argument to equal_paras() to support default values or not
  2313. Revision 1.74 2002/09/10 16:27:28 peter
  2314. * don't insert parast in symtablestack, because typesyms should not be
  2315. searched in the the parast
  2316. Revision 1.73 2002/09/09 19:39:07 peter
  2317. * check return type for forwarddefs also not delphi mode when
  2318. the type is not void
  2319. Revision 1.72 2002/09/09 17:34:15 peter
  2320. * tdicationary.replace added to replace and item in a dictionary. This
  2321. is only allowed for the same name
  2322. * varsyms are inserted in symtable before the types are parsed. This
  2323. fixes the long standing "var longint : longint" bug
  2324. - consume_idlist and idstringlist removed. The loops are inserted
  2325. at the callers place and uses the symtable for duplicate id checking
  2326. Revision 1.71 2002/09/07 15:25:06 peter
  2327. * old logs removed and tabs fixed
  2328. Revision 1.70 2002/09/03 16:26:27 daniel
  2329. * Make Tprocdef.defs protected
  2330. Revision 1.69 2002/09/01 12:11:33 peter
  2331. * calc param_offset after parameters are read, because the calculation
  2332. depends on po_containself
  2333. Revision 1.68 2002/08/25 19:25:20 peter
  2334. * sym.insert_in_data removed
  2335. * symtable.insertvardata/insertconstdata added
  2336. * removed insert_in_data call from symtable.insert, it needs to be
  2337. called separatly. This allows to deref the address calculation
  2338. * procedures now calculate the parast addresses after the procedure
  2339. directives are parsed. This fixes the cdecl parast problem
  2340. * push_addr_param has an extra argument that specifies if cdecl is used
  2341. or not
  2342. Revision 1.67 2002/08/25 11:33:06 peter
  2343. * also check the paratypes when a forward was found
  2344. Revision 1.66 2002/08/19 19:36:44 peter
  2345. * More fixes for cross unit inlining, all tnodes are now implemented
  2346. * Moved pocall_internconst to po_internconst because it is not a
  2347. calling type at all and it conflicted when inlining of these small
  2348. functions was requested
  2349. Revision 1.65 2002/08/18 20:06:24 peter
  2350. * inlining is now also allowed in interface
  2351. * renamed write/load to ppuwrite/ppuload
  2352. * tnode storing in ppu
  2353. * nld,ncon,nbas are already updated for storing in ppu
  2354. Revision 1.64 2002/08/17 09:23:39 florian
  2355. * first part of procinfo rewrite
  2356. Revision 1.63 2002/08/11 14:32:27 peter
  2357. * renamed current_library to objectlibrary
  2358. Revision 1.62 2002/08/11 13:24:12 peter
  2359. * saving of asmsymbols in ppu supported
  2360. * asmsymbollist global is removed and moved into a new class
  2361. tasmlibrarydata that will hold the info of a .a file which
  2362. corresponds with a single module. Added librarydata to tmodule
  2363. to keep the library info stored for the module. In the future the
  2364. objectfiles will also be stored to the tasmlibrarydata class
  2365. * all getlabel/newasmsymbol and friends are moved to the new class
  2366. Revision 1.61 2002/07/26 21:15:40 florian
  2367. * rewrote the system handling
  2368. Revision 1.60 2002/07/20 11:57:55 florian
  2369. * types.pas renamed to defbase.pas because D6 contains a types
  2370. unit so this would conflicts if D6 programms are compiled
  2371. + Willamette/SSE2 instructions to assembler added
  2372. Revision 1.59 2002/07/11 14:41:28 florian
  2373. * start of the new generic parameter handling
  2374. Revision 1.58 2002/07/01 18:46:25 peter
  2375. * internal linker
  2376. * reorganized aasm layer
  2377. Revision 1.57 2002/05/18 13:34:12 peter
  2378. * readded missing revisions
  2379. Revision 1.56 2002/05/16 19:46:42 carl
  2380. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  2381. + try to fix temp allocation (still in ifdef)
  2382. + generic constructor calls
  2383. + start of tassembler / tmodulebase class cleanup
  2384. Revision 1.54 2002/05/12 16:53:08 peter
  2385. * moved entry and exitcode to ncgutil and cgobj
  2386. * foreach gets extra argument for passing local data to the
  2387. iterator function
  2388. * -CR checks also class typecasts at runtime by changing them
  2389. into as
  2390. * fixed compiler to cycle with the -CR option
  2391. * fixed stabs with elf writer, finally the global variables can
  2392. be watched
  2393. * removed a lot of routines from cga unit and replaced them by
  2394. calls to cgobj
  2395. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  2396. u32bit then the other is typecasted also to u32bit without giving
  2397. a rangecheck warning/error.
  2398. * fixed pascal calling method with reversing also the high tree in
  2399. the parast, detected by tcalcst3 test
  2400. Revision 1.53 2002/04/21 19:02:04 peter
  2401. * removed newn and disposen nodes, the code is now directly
  2402. inlined from pexpr
  2403. * -an option that will write the secondpass nodes to the .s file, this
  2404. requires EXTDEBUG define to actually write the info
  2405. * fixed various internal errors and crashes due recent code changes
  2406. Revision 1.52 2002/04/20 21:32:24 carl
  2407. + generic FPC_CHECKPOINTER
  2408. + first parameter offset in stack now portable
  2409. * rename some constants
  2410. + move some cpu stuff to other units
  2411. - remove unused constents
  2412. * fix stacksize for some targets
  2413. * fix generic size problems which depend now on EXTEND_SIZE constant
  2414. Revision 1.51 2002/04/20 15:27:05 carl
  2415. - remove ifdef i386 define
  2416. Revision 1.50 2002/04/19 15:46:02 peter
  2417. * mangledname rewrite, tprocdef.mangledname is now created dynamicly
  2418. in most cases and not written to the ppu
  2419. * add mangeledname_prefix() routine to generate the prefix of
  2420. manglednames depending on the current procedure, object and module
  2421. * removed static procprefix since the mangledname is now build only
  2422. on demand from tprocdef.mangledname
  2423. }