pdecsub.pas 91 KB

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