pdecsub.pas 96 KB

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