pdecsub.pas 92 KB

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