pdecsub.pas 89 KB

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