pdecsub.pas 95 KB

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