pdecsub.pas 93 KB

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