pdecsub.pas 89 KB

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