pdecsub.pas 89 KB

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