pdecsub.pas 91 KB

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