pdecsub.pas 87 KB

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