pdecsub.pas 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 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 defines.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 parameter_dec(aktprocdef:tabstractprocdef);
  34. procedure parse_proc_directives(var pdflags:word);
  35. procedure handle_calling_convention(sym:tprocsym;def:tabstractprocdef);
  36. procedure parse_proc_head(options:tproctypeoption);
  37. procedure parse_proc_dec;
  38. procedure parse_var_proc_directives(var sym : tsym);
  39. procedure parse_object_proc_directives(var sym : tprocsym);
  40. function proc_add_definition(aprocsym:tprocsym;var aprocdef : tprocdef) : boolean;
  41. implementation
  42. uses
  43. {$ifdef delphi}
  44. sysutils,
  45. {$else delphi}
  46. strings,
  47. {$endif delphi}
  48. { common }
  49. cutils,cclasses,
  50. { global }
  51. globtype,globals,verbose,
  52. systems,
  53. { aasm }
  54. aasm,
  55. { symtable }
  56. symbase,symtable,types,
  57. { pass 1 }
  58. node,htypechk,
  59. nmat,nadd,ncal,nset,ncnv,ninl,ncon,nld,nflw,
  60. { parser }
  61. fmodule,scanner,
  62. pbase,pexpr,ptype,pdecl,
  63. { linking }
  64. import,gendef,
  65. { codegen }
  66. cgbase
  67. ;
  68. procedure resetvaluepara(p:tnamedindexitem);
  69. begin
  70. if tsym(p).typ=varsym then
  71. with tvarsym(p) do
  72. if copy(name,1,3)='val' then
  73. aktprocdef.parast.symsearch.rename(name,copy(name,4,length(name)));
  74. end;
  75. procedure parameter_dec(aktprocdef:tabstractprocdef);
  76. {
  77. handle_procvar needs the same changes
  78. }
  79. var
  80. is_procvar : boolean;
  81. sc : tidstringlist;
  82. s : string;
  83. hpos,
  84. storetokenpos : tfileposinfo;
  85. htype,
  86. tt : ttype;
  87. hvs,
  88. vs : tvarsym;
  89. srsym : tsym;
  90. hs1,hs2 : string;
  91. varspez : Tvarspez;
  92. inserthigh : boolean;
  93. tdefaultvalue : tconstsym;
  94. defaultrequired : boolean;
  95. begin
  96. { reset }
  97. defaultrequired:=false;
  98. { parsing a proc or procvar ? }
  99. is_procvar:=(aktprocdef.deftype=procvardef);
  100. if not is_procvar then
  101. hs2:=tprocdef(aktprocdef).mangledname;
  102. consume(_LKLAMMER);
  103. { Delphi/Kylix supports nonsense like }
  104. { procedure p(); }
  105. if try_to_consume(_RKLAMMER) and
  106. not(m_tp7 in aktmodeswitches) then
  107. exit;
  108. inc(testcurobject);
  109. repeat
  110. if try_to_consume(_VAR) then
  111. varspez:=vs_var
  112. else
  113. if try_to_consume(_CONST) then
  114. varspez:=vs_const
  115. else
  116. if (idtoken=_OUT) and (m_out in aktmodeswitches) then
  117. begin
  118. consume(_OUT);
  119. varspez:=vs_out
  120. end
  121. else
  122. varspez:=vs_value;
  123. inserthigh:=false;
  124. tdefaultvalue:=nil;
  125. tt.reset;
  126. { self is only allowed in procvars and class methods }
  127. if (idtoken=_SELF) and
  128. (is_procvar or
  129. (assigned(procinfo^._class) and is_class(procinfo^._class))) then
  130. begin
  131. if varspez <> vs_value then
  132. CGMessage(parser_e_self_call_by_value);
  133. if not is_procvar then
  134. begin
  135. {$ifndef UseNiceNames}
  136. hs2:=hs2+'$'+'self';
  137. {$else UseNiceNames}
  138. hs2:=hs2+tostr(length('self'))+'self';
  139. {$endif UseNiceNames}
  140. htype.setdef(procinfo^._class);
  141. vs:=tvarsym.create('@',htype);
  142. vs.varspez:=vs_var;
  143. { insert the sym in the parasymtable }
  144. tprocdef(aktprocdef).parast.insert(vs);
  145. inc(procinfo^.selfpointer_offset,vs.address);
  146. end;
  147. { must also be included for procvars to allow the proc2procvar }
  148. { type conversions (po_containsself is in po_comp) (JM) }
  149. include(aktprocdef.procoptions,po_containsself);
  150. consume(idtoken);
  151. consume(_COLON);
  152. single_type(tt,hs1,false);
  153. { this must be call-by-value, but we generate already an }
  154. { an error above if that's not the case (JM) }
  155. aktprocdef.concatpara(tt,varspez,nil);
  156. { check the types for procedures only }
  157. if not is_procvar then
  158. CheckTypes(tt.def,procinfo^._class);
  159. end
  160. else
  161. begin
  162. { read identifiers }
  163. sc:=consume_idlist;
  164. {$ifdef fixLeaksOnError}
  165. strContStack.push(sc);
  166. {$endif fixLeaksOnError}
  167. { read type declaration, force reading for value and const paras }
  168. if (token=_COLON) or (varspez=vs_value) then
  169. begin
  170. consume(_COLON);
  171. { check for an open array }
  172. if token=_ARRAY then
  173. begin
  174. consume(_ARRAY);
  175. consume(_OF);
  176. { define range and type of range }
  177. tt.setdef(tarraydef.create(0,-1,s32bittype));
  178. { array of const ? }
  179. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  180. begin
  181. consume(_CONST);
  182. srsym:=searchsymonlyin(systemunit,'TVARREC');
  183. if not assigned(srsym) then
  184. InternalError(1234124);
  185. tarraydef(tt.def).elementtype:=ttypesym(srsym).restype;
  186. tarraydef(tt.def).IsArrayOfConst:=true;
  187. hs1:='array_of_const';
  188. end
  189. else
  190. begin
  191. { define field type }
  192. single_type(tarraydef(tt.def).elementtype,hs1,false);
  193. hs1:='array_of_'+hs1;
  194. end;
  195. inserthigh:=true;
  196. end
  197. else
  198. begin
  199. { open string ? }
  200. if (varspez=vs_var) and
  201. (
  202. (
  203. ((token=_STRING) or (idtoken=_SHORTSTRING)) and
  204. (cs_openstring in aktmoduleswitches) and
  205. not(cs_ansistrings in aktlocalswitches)
  206. ) or
  207. (idtoken=_OPENSTRING)) then
  208. begin
  209. consume(token);
  210. tt:=openshortstringtype;
  211. hs1:='openstring';
  212. inserthigh:=true;
  213. end
  214. else
  215. begin
  216. { everything else }
  217. single_type(tt,hs1,false);
  218. end;
  219. { default parameter }
  220. if (m_default_para in aktmodeswitches) then
  221. begin
  222. if try_to_consume(_EQUAL) then
  223. begin
  224. s:=sc.get(hpos);
  225. if not sc.empty then
  226. Comment(V_Error,'default value only allowed for one parameter');
  227. sc.add(s,hpos);
  228. { prefix 'def' to the parameter name }
  229. tdefaultvalue:=ReadConstant('$def'+Upper(s),hpos);
  230. if assigned(tdefaultvalue) then
  231. tprocdef(aktprocdef).parast.insert(tdefaultvalue);
  232. defaultrequired:=true;
  233. end
  234. else
  235. begin
  236. if defaultrequired then
  237. Comment(V_Error,'default parameter required');
  238. end;
  239. end;
  240. end;
  241. end
  242. else
  243. begin
  244. {$ifndef UseNiceNames}
  245. hs1:='$$$';
  246. {$else UseNiceNames}
  247. hs1:='var';
  248. {$endif UseNiceNames}
  249. tt:=cformaltype;
  250. end;
  251. storetokenpos:=akttokenpos;
  252. while not sc.empty do
  253. begin
  254. s:=sc.get(akttokenpos);
  255. aktprocdef.concatpara(tt,varspez,tdefaultvalue);
  256. { For proc vars we only need the definitions }
  257. if not is_procvar then
  258. begin
  259. {$ifndef UseNiceNames}
  260. hs2:=hs2+'$'+hs1;
  261. {$else UseNiceNames}
  262. hs2:=hs2+tostr(length(hs1))+hs1;
  263. {$endif UseNiceNames}
  264. vs:=tvarsym.create(s,tt);
  265. vs.varspez:=varspez;
  266. { we have to add this to avoid var param to be in registers !!!}
  267. { I don't understand the comment above, }
  268. { but I suppose the comment is wrong and }
  269. { it means that the address of var parameters can be placed }
  270. { in a register (FK) }
  271. if (varspez in [vs_var,vs_const,vs_out]) and push_addr_param(tt.def) then
  272. include(vs.varoptions,vo_regable);
  273. { insert the sym in the parasymtable }
  274. tprocdef(aktprocdef).parast.insert(vs);
  275. { do we need a local copy? Then rename the varsym, do this after the
  276. insert so the dup id checking is done correctly }
  277. if (varspez=vs_value) and
  278. push_addr_param(tt.def) and
  279. not(is_open_array(tt.def) or is_array_of_const(tt.def)) then
  280. tprocdef(aktprocdef).parast.rename(vs.name,'val'+vs.name);
  281. { also need to push a high value? }
  282. if inserthigh then
  283. begin
  284. hvs:=tvarsym.create('$high'+Upper(s),s32bittype);
  285. hvs.varspez:=vs_const;
  286. tprocdef(aktprocdef).parast.insert(hvs);
  287. end;
  288. end;
  289. end;
  290. {$ifdef fixLeaksOnError}
  291. if PStringContainer(strContStack.pop) <> sc then
  292. writeln('problem with strContStack in pdecl (1)');
  293. {$endif fixLeaksOnError}
  294. sc.free;
  295. akttokenpos:=storetokenpos;
  296. end;
  297. { set the new mangled name }
  298. until not try_to_consume(_SEMICOLON);
  299. if not is_procvar then
  300. tprocdef(aktprocdef).setmangledname(hs2);
  301. dec(testcurobject);
  302. consume(_RKLAMMER);
  303. end;
  304. procedure parse_proc_head(options:tproctypeoption);
  305. var
  306. orgsp,sp:stringid;
  307. paramoffset:longint;
  308. sym:tsym;
  309. hs:string;
  310. doinsert : boolean;
  311. st : tsymtable;
  312. srsymtable : tsymtable;
  313. pdl : pprocdeflist;
  314. overloaded_level:word;
  315. storepos,procstartfilepos : tfileposinfo;
  316. i: longint;
  317. procdefs : pprocdeflist;
  318. begin
  319. { Save the position where this procedure really starts }
  320. procstartfilepos:=akttokenpos;
  321. aktprocdef:=nil;
  322. if (options=potype_operator) then
  323. begin
  324. sp:=overloaded_names[optoken];
  325. orgsp:=sp;
  326. end
  327. else
  328. begin
  329. sp:=pattern;
  330. orgsp:=orgpattern;
  331. consume(_ID);
  332. end;
  333. { examine interface map: function/procedure iname.functionname=locfuncname }
  334. if parse_only and
  335. assigned(procinfo^._class) and
  336. assigned(procinfo^._class.implementedinterfaces) and
  337. (procinfo^._class.implementedinterfaces.count>0) and
  338. try_to_consume(_POINT) then
  339. begin
  340. storepos:=akttokenpos;
  341. akttokenpos:=procstartfilepos;
  342. { get interface syms}
  343. searchsym(sp,sym,srsymtable);
  344. if not assigned(sym) then
  345. begin
  346. identifier_not_found(orgsp);
  347. sym:=generrorsym;
  348. end;
  349. akttokenpos:=storepos;
  350. { load proc name }
  351. if sym.typ=typesym then
  352. i:=procinfo^._class.implementedinterfaces.searchintf(ttypesym(sym).restype.def);
  353. { qualifier is interface name? }
  354. if (sym.typ<>typesym) or (ttypesym(sym).restype.def.deftype<>objectdef) or
  355. (i=-1) then
  356. begin
  357. Message(parser_e_interface_id_expected);
  358. aktprocsym:=nil;
  359. end
  360. else
  361. begin
  362. aktprocsym:=tprocsym(procinfo^._class.implementedinterfaces.interfaces(i).symtable.search(sp));
  363. { the method can be declared after the mapping FK
  364. if not(assigned(aktprocsym)) then
  365. Message(parser_e_methode_id_expected);
  366. }
  367. end;
  368. consume(_ID);
  369. consume(_EQUAL);
  370. if (token=_ID) { and assigned(aktprocsym) } then
  371. procinfo^._class.implementedinterfaces.addmappings(i,sp,pattern);
  372. consume(_ID);
  373. exit;
  374. end;
  375. { method ? }
  376. if not(parse_only) and
  377. (lexlevel=normal_function_level) and
  378. try_to_consume(_POINT) then
  379. begin
  380. { search for object name }
  381. storepos:=akttokenpos;
  382. akttokenpos:=procstartfilepos;
  383. searchsym(sp,sym,srsymtable);
  384. if not assigned(sym) then
  385. begin
  386. identifier_not_found(orgsp);
  387. sym:=generrorsym;
  388. end;
  389. akttokenpos:=storepos;
  390. { consume proc name }
  391. sp:=pattern;
  392. orgsp:=orgpattern;
  393. procstartfilepos:=akttokenpos;
  394. consume(_ID);
  395. { qualifier is class name ? }
  396. if (sym.typ<>typesym) or
  397. (ttypesym(sym).restype.def.deftype<>objectdef) then
  398. begin
  399. Message(parser_e_class_id_expected);
  400. aktprocsym:=nil;
  401. aktprocdef:=nil;
  402. end
  403. else
  404. begin
  405. { used to allow private syms to be seen }
  406. aktobjectdef:=tobjectdef(ttypesym(sym).restype.def);
  407. procinfo^._class:=tobjectdef(ttypesym(sym).restype.def);
  408. aktprocsym:=tprocsym(procinfo^._class.symtable.search(sp));
  409. {The procedure has been found. So it is
  410. a global one. Set the flags to mark this.}
  411. procinfo^.flags:=procinfo^.flags or pi_is_global;
  412. aktobjectdef:=nil;
  413. { we solve this below }
  414. if not(assigned(aktprocsym)) then
  415. Message(parser_e_methode_id_expected);
  416. end;
  417. end
  418. else
  419. begin
  420. { check for constructor/destructor which is not allowed here }
  421. if (not parse_only) and
  422. (options in [potype_constructor,potype_destructor]) then
  423. Message(parser_e_constructors_always_objects);
  424. akttokenpos:=procstartfilepos;
  425. aktprocsym:=tprocsym(symtablestack.search(sp));
  426. if not(parse_only) then
  427. begin
  428. {The procedure we prepare for is in the implementation
  429. part of the unit we compile. It is also possible that we
  430. are compiling a program, which is also some kind of
  431. implementaion part.
  432. We need to find out if the procedure is global. If it is
  433. global, it is in the global symtable.}
  434. if not assigned(aktprocsym) and
  435. (symtablestack.symtabletype=staticsymtable) and
  436. assigned(symtablestack.next) and
  437. (symtablestack.next.unitid=0) then
  438. begin
  439. {Search the procedure in the global symtable.}
  440. aktprocsym:=tprocsym(symtablestack.next.search(sp));
  441. if assigned(aktprocsym) then
  442. begin
  443. {Check if it is a procedure.}
  444. if aktprocsym.typ<>procsym then
  445. DuplicateSym(aktprocsym);
  446. {The procedure has been found. So it is
  447. a global one. Set the flags to mark this.}
  448. procinfo^.flags:=procinfo^.flags or pi_is_global;
  449. end;
  450. end;
  451. end;
  452. end;
  453. { Create the mangledname }
  454. {$ifndef UseNiceNames}
  455. if assigned(procinfo^._class) then
  456. begin
  457. if (pos('_$$_',procprefix)=0) then
  458. hs:=procprefix+'_$$_'+upper(procinfo^._class.objname^)+'_$$_'+sp
  459. else
  460. hs:=procprefix+'_$'+sp;
  461. end
  462. else
  463. begin
  464. if lexlevel=normal_function_level then
  465. hs:=procprefix+'_'+sp
  466. else
  467. hs:=procprefix+'_$'+sp;
  468. end;
  469. {$else UseNiceNames}
  470. if assigned(procinfo^._class) then
  471. begin
  472. if (pos('_5Class_',procprefix)=0) then
  473. hs:=procprefix+'_5Class_'+procinfo^._class.name^+'_'+tostr(length(sp))+sp
  474. else
  475. hs:=procprefix+'_'+tostr(length(sp))+sp;
  476. end
  477. else
  478. begin
  479. if lexlevel=normal_function_level then
  480. hs:=procprefix+'_'+tostr(length(sp))+sp
  481. else
  482. hs:=lowercase(procprefix)+'_'+tostr(length(sp))+sp;
  483. end;
  484. {$endif UseNiceNames}
  485. doinsert:=true;
  486. if assigned(aktprocsym) then
  487. begin
  488. { Check if overloaded is a procsym }
  489. if aktprocsym.typ<>procsym then
  490. begin
  491. { when the other symbol is a unit symbol then hide the unit
  492. symbol. Only in tp mode because it's bad programming }
  493. if (m_tp in aktmodeswitches) and
  494. (aktprocsym.typ=unitsym) then
  495. begin
  496. aktprocsym.owner.rename(aktprocsym.name,'hidden'+aktprocsym.name);
  497. end
  498. else
  499. begin
  500. { we use a different error message for tp7 so it looks more compatible }
  501. if (m_fpc in aktmodeswitches) then
  502. Message1(parser_e_overloaded_no_procedure,aktprocsym.realname)
  503. else
  504. DuplicateSym(aktprocsym);
  505. { don't reinsert as that will generated another error }
  506. doinsert:=false;
  507. end;
  508. { generate a new aktprocsym }
  509. aktprocsym:=nil;
  510. end;
  511. end;
  512. { test again if assigned, it can be reset to recover }
  513. if not assigned(aktprocsym) then
  514. begin
  515. { create a new procsym and set the real filepos }
  516. akttokenpos:=procstartfilepos;
  517. { for operator we have only one procsym for each overloaded
  518. operation }
  519. if (options=potype_operator) then
  520. begin
  521. { is the current overload sym already in the current unit }
  522. if assigned(overloaded_operators[optoken]) and
  523. (overloaded_operators[optoken].owner=symtablestack) then
  524. aktprocsym:=overloaded_operators[optoken]
  525. else
  526. begin
  527. { create the procsym with saving the original case }
  528. aktprocsym:=tprocsym.create('$'+sp);
  529. { add already known overloaded defs }
  530. if assigned(overloaded_operators[optoken]) then
  531. begin
  532. pdl:=overloaded_operators[optoken].defs;
  533. while assigned(pdl) do
  534. begin
  535. aktprocsym.addprocdef(pdl^.def);
  536. pdl:=pdl^.next;
  537. end;
  538. end;
  539. end;
  540. end
  541. else
  542. aktprocsym:=tprocsym.create(orgsp);
  543. if doinsert then
  544. symtablestack.insert(aktprocsym);
  545. end;
  546. st:=symtablestack;
  547. aktprocdef:=tprocdef.create;
  548. aktprocdef.symtablelevel:=symtablestack.symtablelevel;
  549. if assigned(procinfo^._class) then
  550. aktprocdef._class := procinfo^._class;
  551. { set the options from the caller (podestructor or poconstructor) }
  552. aktprocdef.proctypeoption:=options;
  553. { calculate the offset of the parameters }
  554. paramoffset:=8;
  555. { calculate frame pointer offset }
  556. if lexlevel>normal_function_level then
  557. begin
  558. procinfo^.framepointer_offset:=paramoffset;
  559. inc(paramoffset,target_info.size_of_pointer);
  560. { this is needed to get correct framepointer push for local
  561. forward functions !! }
  562. aktprocdef.parast.symtablelevel:=lexlevel;
  563. end;
  564. if assigned (procinfo^._Class) and
  565. is_object(procinfo^._Class) and
  566. (aktprocdef.proctypeoption in [potype_constructor,potype_destructor]) then
  567. inc(paramoffset,target_info.size_of_pointer);
  568. { self pointer offset }
  569. { self isn't pushed in nested procedure of methods }
  570. if assigned(procinfo^._class) and (lexlevel=normal_function_level) then
  571. begin
  572. procinfo^.selfpointer_offset:=paramoffset;
  573. if assigned(aktprocdef) and
  574. not(po_containsself in aktprocdef.procoptions) then
  575. inc(paramoffset,target_info.size_of_pointer);
  576. end;
  577. { con/-destructor flag ? }
  578. if assigned (procinfo^._Class) and
  579. is_class(procinfo^._class) and
  580. (aktprocdef.proctypeoption in [potype_destructor,potype_constructor]) then
  581. inc(paramoffset,target_info.size_of_pointer);
  582. procinfo^.para_offset:=paramoffset;
  583. aktprocdef.parast.datasize:=0;
  584. { add procsym to the procdef }
  585. aktprocdef.procsym:=aktprocsym;
  586. { save file position }
  587. aktprocdef.fileinfo:=procstartfilepos;
  588. { store mangledname }
  589. aktprocdef.setmangledname(hs);
  590. if not parse_only then
  591. begin
  592. overloaded_level:=1;
  593. { we need another procprefix !!! }
  594. { count, but only those in the same unit !!}
  595. procdefs:=aktprocsym.defs;
  596. while assigned(procdefs) and
  597. (procdefs^.def.owner.symtabletype in [globalsymtable,staticsymtable]) do
  598. begin
  599. { only count already implemented functions }
  600. if not(procdefs^.def.forwarddef) then
  601. inc(overloaded_level);
  602. procdefs:=procdefs^.next;
  603. end;
  604. if overloaded_level>0 then
  605. procprefix:=hs+'$'+tostr(overloaded_level)+'$'
  606. else
  607. procprefix:=hs+'$';
  608. end;
  609. { this must also be inserted in the right symtable !! PM }
  610. { otherwise we get subbtle problems with
  611. definitions of args defs in staticsymtable for
  612. implementation of a global method }
  613. if token=_LKLAMMER then
  614. parameter_dec(aktprocdef);
  615. { so we only restore the symtable now }
  616. symtablestack:=st;
  617. if (options=potype_operator) then
  618. overloaded_operators[optoken]:=aktprocsym;
  619. end;
  620. procedure parse_proc_dec;
  621. var
  622. hs : string;
  623. isclassmethod : boolean;
  624. begin
  625. inc(lexlevel);
  626. { read class method }
  627. if token=_CLASS then
  628. begin
  629. consume(_CLASS);
  630. isclassmethod:=true;
  631. end
  632. else
  633. isclassmethod:=false;
  634. case token of
  635. _FUNCTION : begin
  636. consume(_FUNCTION);
  637. parse_proc_head(potype_none);
  638. if token<>_COLON then
  639. begin
  640. if assigned(aktprocsym) and
  641. not(is_interface(aktprocdef._class)) and
  642. not(aktprocdef.forwarddef) or
  643. (m_repeat_forward in aktmodeswitches) then
  644. begin
  645. consume(_COLON);
  646. consume_all_until(_SEMICOLON);
  647. end;
  648. end
  649. else
  650. begin
  651. consume(_COLON);
  652. inc(testcurobject);
  653. single_type(aktprocdef.rettype,hs,false);
  654. aktprocdef.test_if_fpu_result;
  655. dec(testcurobject);
  656. end;
  657. end;
  658. _PROCEDURE : begin
  659. consume(_PROCEDURE);
  660. parse_proc_head(potype_none);
  661. if assigned(aktprocsym) then
  662. aktprocdef.rettype:=voidtype;
  663. end;
  664. _CONSTRUCTOR : begin
  665. consume(_CONSTRUCTOR);
  666. parse_proc_head(potype_constructor);
  667. if assigned(procinfo^._class) and
  668. is_class(procinfo^._class) then
  669. begin
  670. { CLASS constructors return the created instance }
  671. aktprocdef.rettype.setdef(procinfo^._class);
  672. end
  673. else
  674. begin
  675. { OBJECT constructors return a boolean }
  676. aktprocdef.rettype:=booltype;
  677. end;
  678. end;
  679. _DESTRUCTOR : begin
  680. consume(_DESTRUCTOR);
  681. parse_proc_head(potype_destructor);
  682. aktprocdef.rettype:=voidtype;
  683. end;
  684. _OPERATOR : begin
  685. if lexlevel>normal_function_level then
  686. Message(parser_e_no_local_operator);
  687. consume(_OPERATOR);
  688. if (token in [first_overloaded..last_overloaded]) then
  689. begin
  690. procinfo^.flags:=procinfo^.flags or pi_operator;
  691. optoken:=token;
  692. end
  693. else
  694. begin
  695. Message(parser_e_overload_operator_failed);
  696. { Use the dummy NOTOKEN that is also declared
  697. for the overloaded_operator[] }
  698. optoken:=NOTOKEN;
  699. end;
  700. consume(Token);
  701. parse_proc_head(potype_operator);
  702. if token<>_ID then
  703. begin
  704. otsym:=nil;
  705. if not(m_result in aktmodeswitches) then
  706. consume(_ID);
  707. end
  708. else
  709. begin
  710. otsym:=tvarsym.create(pattern,voidtype);
  711. consume(_ID);
  712. end;
  713. if not try_to_consume(_COLON) then
  714. begin
  715. consume(_COLON);
  716. aktprocdef.rettype:=generrortype;
  717. consume_all_until(_SEMICOLON);
  718. end
  719. else
  720. begin
  721. single_type(aktprocdef.rettype,hs,false);
  722. aktprocdef.test_if_fpu_result;
  723. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  724. ((aktprocdef.rettype.def.deftype<>
  725. orddef) or (torddef(aktprocdef.
  726. rettype.def).typ<>bool8bit)) then
  727. Message(parser_e_comparative_operator_return_boolean);
  728. if assigned(otsym) then
  729. otsym.vartype.def:=aktprocdef.rettype.def;
  730. { We need to add the return type in the mangledname
  731. to allow overloading with just different results !! (PM) }
  732. aktprocdef.setmangledname(
  733. aktprocdef.mangledname+'$$'+hs);
  734. if (optoken=_ASSIGNMENT) and
  735. is_equal(aktprocdef.rettype.def,
  736. tvarsym(aktprocdef.parast.symindex.first).vartype.def) then
  737. message(parser_e_no_such_assignment)
  738. else if not isoperatoracceptable(aktprocdef,optoken) then
  739. Message(parser_e_overload_impossible);
  740. end;
  741. end;
  742. end;
  743. if isclassmethod and
  744. assigned(aktprocsym) then
  745. include(aktprocdef.procoptions,po_classmethod);
  746. { support procedure proc;stdcall export; in Delphi mode only }
  747. if not((m_delphi in aktmodeswitches) and
  748. is_proc_directive(token)) then
  749. consume(_SEMICOLON);
  750. dec(lexlevel);
  751. end;
  752. {****************************************************************************
  753. Procedure directive handlers
  754. ****************************************************************************}
  755. procedure pd_far;
  756. begin
  757. Message(parser_w_proc_far_ignored);
  758. end;
  759. procedure pd_near;
  760. begin
  761. Message(parser_w_proc_near_ignored);
  762. end;
  763. procedure pd_export;
  764. begin
  765. if assigned(procinfo^._class) then
  766. Message(parser_e_methods_dont_be_export);
  767. if lexlevel<>normal_function_level then
  768. Message(parser_e_dont_nest_export);
  769. { only os/2 needs this }
  770. if target_info.target=target_i386_os2 then
  771. begin
  772. aktprocdef.aliasnames.insert(aktprocsym.realname);
  773. procinfo^.exported:=true;
  774. if cs_link_deffile in aktglobalswitches then
  775. deffile.AddExport(aktprocdef.mangledname);
  776. end;
  777. end;
  778. procedure pd_forward;
  779. begin
  780. aktprocdef.forwarddef:=true;
  781. end;
  782. procedure pd_alias;
  783. begin
  784. consume(_COLON);
  785. aktprocdef.aliasnames.insert(get_stringconst);
  786. end;
  787. procedure pd_asmname;
  788. begin
  789. aktprocdef.setmangledname(target_info.Cprefix+pattern);
  790. aktprocdef.has_mangledname:=true;
  791. if token=_CCHAR then
  792. consume(_CCHAR)
  793. else
  794. consume(_CSTRING);
  795. { we don't need anything else }
  796. aktprocdef.forwarddef:=false;
  797. end;
  798. procedure pd_intern;
  799. begin
  800. consume(_COLON);
  801. aktprocdef.extnumber:=get_intconst;
  802. end;
  803. procedure pd_interrupt;
  804. begin
  805. {$ifndef i386}
  806. Message(parser_w_proc_interrupt_ignored);
  807. {$else i386}
  808. if lexlevel<>normal_function_level then
  809. Message(parser_e_dont_nest_interrupt);
  810. {$endif i386}
  811. end;
  812. procedure pd_abstract;
  813. begin
  814. if (po_virtualmethod in aktprocdef.procoptions) then
  815. include(aktprocdef.procoptions,po_abstractmethod)
  816. else
  817. Message(parser_e_only_virtual_methods_abstract);
  818. { the method is defined }
  819. aktprocdef.forwarddef:=false;
  820. end;
  821. procedure pd_virtual;
  822. {$ifdef WITHDMT}
  823. var
  824. pt : tnode;
  825. {$endif WITHDMT}
  826. begin
  827. if (aktprocdef.proctypeoption=potype_constructor) and
  828. is_object(aktprocdef._class) then
  829. Message(parser_e_constructor_cannot_be_not_virtual);
  830. {$ifdef WITHDMT}
  831. if is_object(aktprocdef._class) and
  832. (token<>_SEMICOLON) then
  833. begin
  834. { any type of parameter is allowed here! }
  835. pt:=comp_expr(true);
  836. if is_constintnode(pt) then
  837. begin
  838. include(aktprocdef.procoptions,po_msgint);
  839. aktprocdef.messageinf.i:=pt^.value;
  840. end
  841. else
  842. Message(parser_e_ill_msg_expr);
  843. disposetree(pt);
  844. end;
  845. {$endif WITHDMT}
  846. end;
  847. procedure pd_static;
  848. begin
  849. if (cs_static_keyword in aktmoduleswitches) then
  850. begin
  851. include(aktprocsym.symoptions,sp_static);
  852. include(aktprocdef.procoptions,po_staticmethod);
  853. end;
  854. end;
  855. procedure pd_override;
  856. begin
  857. if not(is_class_or_interface(aktprocdef._class)) then
  858. Message(parser_e_no_object_override);
  859. end;
  860. procedure pd_overload;
  861. begin
  862. include(aktprocsym.symoptions,sp_has_overloaded);
  863. end;
  864. procedure pd_message;
  865. var
  866. pt : tnode;
  867. begin
  868. { check parameter type }
  869. if not(po_containsself in aktprocdef.procoptions) and
  870. ((aktprocdef.minparacount<>1) or
  871. (aktprocdef.maxparacount<>1) or
  872. (TParaItem(aktprocdef.Para.first).paratyp<>vs_var)) then
  873. Message(parser_e_ill_msg_param);
  874. pt:=comp_expr(true);
  875. if pt.nodetype=stringconstn then
  876. begin
  877. include(aktprocdef.procoptions,po_msgstr);
  878. aktprocdef.messageinf.str:=strnew(tstringconstnode(pt).value_str);
  879. end
  880. else
  881. if is_constintnode(pt) then
  882. begin
  883. include(aktprocdef.procoptions,po_msgint);
  884. aktprocdef.messageinf.i:=tordconstnode(pt).value;
  885. end
  886. else
  887. Message(parser_e_ill_msg_expr);
  888. pt.free;
  889. end;
  890. procedure pd_reintroduce;
  891. begin
  892. Message1(parser_w_proc_directive_ignored,'REINTRODUCE');
  893. end;
  894. procedure pd_syscall;
  895. begin
  896. aktprocdef.forwarddef:=false;
  897. aktprocdef.extnumber:=get_intconst;
  898. end;
  899. procedure pd_external;
  900. {
  901. If import_dll=nil the procedure is assumed to be in another
  902. object file. In that object file it should have the name to
  903. which import_name is pointing to. Otherwise, the procedure is
  904. assumed to be in the DLL to which import_dll is pointing to. In
  905. that case either import_nr<>0 or import_name<>nil is true, so
  906. the procedure is either imported by number or by name. (DM)
  907. }
  908. var
  909. import_dll,
  910. import_name : string;
  911. import_nr : word;
  912. begin
  913. aktprocdef.forwarddef:=false;
  914. { forbid local external procedures }
  915. if lexlevel>normal_function_level then
  916. Message(parser_e_no_local_external);
  917. { If the procedure should be imported from a DLL, a constant string follows.
  918. This isn't really correct, an contant string expression follows
  919. so we check if an semicolon follows, else a string constant have to
  920. follow (FK) }
  921. import_nr:=0;
  922. import_name:='';
  923. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  924. begin
  925. import_dll:=get_stringconst;
  926. if (idtoken=_NAME) then
  927. begin
  928. consume(_NAME);
  929. import_name:=get_stringconst;
  930. end;
  931. if (idtoken=_INDEX) then
  932. begin
  933. {After the word index follows the index number in the DLL.}
  934. consume(_INDEX);
  935. import_nr:=get_intconst;
  936. end;
  937. { default is to used the realname of the procedure }
  938. if (import_nr=0) and (import_name='') then
  939. import_name:=aktprocsym.realname;
  940. { create importlib if not already done }
  941. if not(current_module.uses_imports) then
  942. begin
  943. current_module.uses_imports:=true;
  944. importlib.preparelib(current_module.modulename^);
  945. end;
  946. {$ifdef notused}
  947. if not(m_repeat_forward in aktmodeswitches) and
  948. { if the procedure is declared with the overload option }
  949. { it requires a full declaration in the implementation part }
  950. not(sp_has_overloaded in aktprocsym.symoptions) then
  951. begin
  952. { we can only have one overloaded here ! }
  953. if assigned(aktprocdef.defs.next) then
  954. importlib.importprocedure(aktprocdef.defs.next.mangledname,
  955. import_dll,import_nr,import_name)
  956. else
  957. importlib.importprocedure(aktprocdef.mangledname,import_dll,import_nr,import_name);
  958. end
  959. else
  960. {$endif notused}
  961. importlib.importprocedure(aktprocdef.mangledname,import_dll,import_nr,import_name);
  962. end
  963. else
  964. begin
  965. if (idtoken=_NAME) then
  966. begin
  967. consume(_NAME);
  968. import_name:=get_stringconst;
  969. aktprocdef.setmangledname(import_name);
  970. aktprocdef.has_mangledname:=true;
  971. end;
  972. end;
  973. end;
  974. type
  975. pd_handler=procedure;
  976. proc_dir_rec=record
  977. idtok : ttoken;
  978. pd_flags : longint;
  979. handler : pd_handler;
  980. pocall : tproccalloption;
  981. pooption : tprocoptions;
  982. mutexclpocall : tproccalloptions;
  983. mutexclpotype : tproctypeoptions;
  984. mutexclpo : tprocoptions;
  985. end;
  986. const
  987. {Should contain the number of procedure directives we support.}
  988. num_proc_directives=36;
  989. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  990. (
  991. (
  992. idtok:_ABSTRACT;
  993. pd_flags : pd_interface+pd_object+pd_notobjintf;
  994. handler : {$ifdef FPCPROCVAR}@{$endif}pd_abstract;
  995. pocall : pocall_none;
  996. pooption : [po_abstractmethod];
  997. mutexclpocall : [pocall_internproc,pocall_inline];
  998. mutexclpotype : [potype_constructor,potype_destructor];
  999. mutexclpo : [po_exports,po_interrupt,po_external]
  1000. ),(
  1001. idtok:_ALIAS;
  1002. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1003. handler : {$ifdef FPCPROCVAR}@{$endif}pd_alias;
  1004. pocall : pocall_none;
  1005. pooption : [];
  1006. mutexclpocall : [pocall_inline];
  1007. mutexclpotype : [];
  1008. mutexclpo : [po_external]
  1009. ),(
  1010. idtok:_ASMNAME;
  1011. pd_flags : pd_interface+pd_implemen+pd_notobjintf;
  1012. handler : {$ifdef FPCPROCVAR}@{$endif}pd_asmname;
  1013. pocall : pocall_cdecl;
  1014. pooption : [po_external];
  1015. mutexclpocall : [pocall_internproc,pocall_inline];
  1016. mutexclpotype : [];
  1017. mutexclpo : [po_external]
  1018. ),(
  1019. idtok:_ASSEMBLER;
  1020. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1021. handler : nil;
  1022. pocall : pocall_none;
  1023. pooption : [po_assembler];
  1024. mutexclpocall : [];
  1025. mutexclpotype : [];
  1026. mutexclpo : [po_external]
  1027. ),(
  1028. idtok:_CDECL;
  1029. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1030. handler : nil;
  1031. pocall : pocall_cdecl;
  1032. pooption : [];
  1033. mutexclpocall : [];
  1034. mutexclpotype : [];
  1035. mutexclpo : [po_assembler,po_external]
  1036. ),(
  1037. idtok:_DYNAMIC;
  1038. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1039. handler : {$ifdef FPCPROCVAR}@{$endif}pd_virtual;
  1040. pocall : pocall_none;
  1041. pooption : [po_virtualmethod];
  1042. mutexclpocall : [pocall_internproc,pocall_inline];
  1043. mutexclpotype : [];
  1044. mutexclpo : [po_exports,po_interrupt,po_external]
  1045. ),(
  1046. idtok:_EXPORT;
  1047. pd_flags : pd_body+pd_global+pd_interface+pd_implemen{??}+pd_notobjintf;
  1048. handler : {$ifdef FPCPROCVAR}@{$endif}pd_export;
  1049. pocall : pocall_none;
  1050. pooption : [po_exports];
  1051. mutexclpocall : [pocall_internproc,pocall_inline];
  1052. mutexclpotype : [];
  1053. mutexclpo : [po_external,po_interrupt]
  1054. ),(
  1055. idtok:_EXTERNAL;
  1056. pd_flags : pd_implemen+pd_interface+pd_notobjintf;
  1057. handler : {$ifdef FPCPROCVAR}@{$endif}pd_external;
  1058. pocall : pocall_none;
  1059. pooption : [po_external];
  1060. mutexclpocall : [pocall_internproc,pocall_inline,pocall_palmossyscall];
  1061. mutexclpotype : [];
  1062. mutexclpo : [po_exports,po_interrupt,po_assembler]
  1063. ),(
  1064. idtok:_FAR;
  1065. pd_flags : pd_implemen+pd_body+pd_interface+pd_procvar+pd_notobjintf;
  1066. handler : {$ifdef FPCPROCVAR}@{$endif}pd_far;
  1067. pocall : pocall_none;
  1068. pooption : [];
  1069. mutexclpocall : [pocall_internproc,pocall_inline];
  1070. mutexclpotype : [];
  1071. mutexclpo : []
  1072. ),(
  1073. idtok:_FAR16;
  1074. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1075. handler : nil;
  1076. pocall : pocall_far16;
  1077. pooption : [];
  1078. mutexclpocall : [];
  1079. mutexclpotype : [];
  1080. mutexclpo : [po_external,po_leftright]
  1081. ),(
  1082. idtok:_FORWARD;
  1083. pd_flags : pd_implemen+pd_notobjintf;
  1084. handler : {$ifdef FPCPROCVAR}@{$endif}pd_forward;
  1085. pocall : pocall_none;
  1086. pooption : [];
  1087. mutexclpocall : [pocall_internproc,pocall_inline];
  1088. mutexclpotype : [];
  1089. mutexclpo : [po_external]
  1090. ),(
  1091. idtok:_FPCCALL;
  1092. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1093. handler : nil;
  1094. pocall : pocall_fpccall;
  1095. pooption : [];
  1096. mutexclpocall : [];
  1097. mutexclpotype : [];
  1098. mutexclpo : [po_leftright]
  1099. ),(
  1100. idtok:_INLINE;
  1101. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1102. handler : nil;
  1103. pocall : pocall_inline;
  1104. pooption : [];
  1105. mutexclpocall : [];
  1106. mutexclpotype : [potype_constructor,potype_destructor];
  1107. mutexclpo : [po_exports,po_external,po_interrupt]
  1108. ),(
  1109. idtok:_INTERNCONST;
  1110. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1111. handler : {$ifdef FPCPROCVAR}@{$endif}pd_intern;
  1112. pocall : pocall_internconst;
  1113. pooption : [];
  1114. mutexclpocall : [];
  1115. mutexclpotype : [potype_operator];
  1116. mutexclpo : []
  1117. ),(
  1118. idtok:_INTERNPROC;
  1119. pd_flags : pd_implemen+pd_notobjintf;
  1120. handler : {$ifdef FPCPROCVAR}@{$endif}pd_intern;
  1121. pocall : pocall_internproc;
  1122. pooption : [];
  1123. mutexclpocall : [];
  1124. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1125. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck,po_leftright]
  1126. ),(
  1127. idtok:_INTERRUPT;
  1128. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1129. handler : {$ifdef FPCPROCVAR}@{$endif}pd_interrupt;
  1130. pocall : pocall_none;
  1131. pooption : [po_interrupt];
  1132. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_cppdecl,
  1133. pocall_inline,pocall_pascal,pocall_system,pocall_far16,pocall_fpccall];
  1134. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1135. mutexclpo : [po_external,po_leftright,po_clearstack]
  1136. ),(
  1137. idtok:_IOCHECK;
  1138. pd_flags : pd_implemen+pd_body+pd_notobjintf;
  1139. handler : nil;
  1140. pocall : pocall_none;
  1141. pooption : [po_iocheck];
  1142. mutexclpocall : [pocall_internproc];
  1143. mutexclpotype : [];
  1144. mutexclpo : [po_external]
  1145. ),(
  1146. idtok:_MESSAGE;
  1147. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1148. handler : {$ifdef FPCPROCVAR}@{$endif}pd_message;
  1149. pocall : pocall_none;
  1150. pooption : []; { can be po_msgstr or po_msgint }
  1151. mutexclpocall : [pocall_inline,pocall_internproc];
  1152. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1153. mutexclpo : [po_interrupt,po_external]
  1154. ),(
  1155. idtok:_NEAR;
  1156. pd_flags : pd_implemen+pd_body+pd_procvar+pd_notobjintf;
  1157. handler : {$ifdef FPCPROCVAR}@{$endif}pd_near;
  1158. pocall : pocall_none;
  1159. pooption : [];
  1160. mutexclpocall : [pocall_internproc];
  1161. mutexclpotype : [];
  1162. mutexclpo : []
  1163. ),(
  1164. idtok:_OVERLOAD;
  1165. pd_flags : pd_implemen+pd_interface+pd_body;
  1166. handler : {$ifdef FPCPROCVAR}@{$endif}pd_overload;
  1167. pocall : pocall_none;
  1168. pooption : [po_overload];
  1169. mutexclpocall : [pocall_internproc];
  1170. mutexclpotype : [];
  1171. mutexclpo : []
  1172. ),(
  1173. idtok:_OVERRIDE;
  1174. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1175. handler : {$ifdef FPCPROCVAR}@{$endif}pd_override;
  1176. pocall : pocall_none;
  1177. pooption : [po_overridingmethod,po_virtualmethod];
  1178. mutexclpocall : [pocall_inline,pocall_internproc];
  1179. mutexclpotype : [];
  1180. mutexclpo : [po_exports,po_external,po_interrupt]
  1181. ),(
  1182. idtok:_PASCAL;
  1183. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1184. handler : nil;
  1185. pocall : pocall_pascal;
  1186. pooption : [];
  1187. mutexclpocall : [];
  1188. mutexclpotype : [];
  1189. mutexclpo : [po_external]
  1190. ),(
  1191. idtok:_POPSTACK;
  1192. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1193. handler : nil;
  1194. pocall : pocall_none;
  1195. pooption : [po_clearstack];
  1196. mutexclpocall : [pocall_inline,pocall_internproc,pocall_stdcall];
  1197. mutexclpotype : [];
  1198. mutexclpo : [po_assembler,po_external]
  1199. ),(
  1200. idtok:_PUBLIC;
  1201. pd_flags : pd_implemen+pd_body+pd_global+pd_notobject+pd_notobjintf;
  1202. handler : nil;
  1203. pocall : pocall_none;
  1204. pooption : [];
  1205. mutexclpocall : [pocall_internproc,pocall_inline];
  1206. mutexclpotype : [];
  1207. mutexclpo : [po_external]
  1208. ),(
  1209. idtok:_REGISTER;
  1210. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1211. handler : nil;
  1212. pocall : pocall_register;
  1213. pooption : [];
  1214. mutexclpocall : [];
  1215. mutexclpotype : [];
  1216. mutexclpo : [po_external]
  1217. ),(
  1218. idtok:_REINTRODUCE;
  1219. pd_flags : pd_interface+pd_object;
  1220. handler : {$ifdef FPCPROCVAR}@{$endif}pd_reintroduce;
  1221. pocall : pocall_none;
  1222. pooption : [];
  1223. mutexclpocall : [];
  1224. mutexclpotype : [];
  1225. mutexclpo : []
  1226. ),(
  1227. idtok:_SAFECALL;
  1228. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1229. handler : nil;
  1230. pocall : pocall_safecall;
  1231. pooption : [];
  1232. mutexclpocall : [];
  1233. mutexclpotype : [];
  1234. mutexclpo : [po_external]
  1235. ),(
  1236. idtok:_SAVEREGISTERS;
  1237. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar+pd_notobjintf;
  1238. handler : nil;
  1239. pocall : pocall_none;
  1240. pooption : [po_saveregisters];
  1241. mutexclpocall : [pocall_internproc];
  1242. mutexclpotype : [];
  1243. mutexclpo : [po_external]
  1244. ),(
  1245. idtok:_STATIC;
  1246. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1247. handler : {$ifdef FPCPROCVAR}@{$endif}pd_static;
  1248. pocall : pocall_none;
  1249. pooption : [po_staticmethod];
  1250. mutexclpocall : [pocall_inline,pocall_internproc];
  1251. mutexclpotype : [potype_constructor,potype_destructor];
  1252. mutexclpo : [po_external,po_interrupt,po_exports]
  1253. ),(
  1254. idtok:_STDCALL;
  1255. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1256. handler : nil;
  1257. pocall : pocall_stdcall;
  1258. pooption : [];
  1259. mutexclpocall : [];
  1260. mutexclpotype : [];
  1261. mutexclpo : [po_external]
  1262. ),(
  1263. idtok:_SYSCALL;
  1264. pd_flags : pd_interface+pd_implemen+pd_notobjintf;
  1265. handler : {$ifdef FPCPROCVAR}@{$endif}pd_syscall;
  1266. pocall : pocall_palmossyscall;
  1267. pooption : [];
  1268. mutexclpocall : [];
  1269. mutexclpotype : [];
  1270. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1271. ),(
  1272. idtok:_SYSTEM;
  1273. pd_flags : pd_implemen+pd_notobjintf;
  1274. handler : nil;
  1275. pocall : pocall_system;
  1276. pooption : [];
  1277. mutexclpocall : [];
  1278. mutexclpotype : [];
  1279. mutexclpo : [po_external,po_assembler,po_interrupt]
  1280. ),(
  1281. idtok:_VIRTUAL;
  1282. pd_flags : pd_interface+pd_object+pd_notobjintf;
  1283. handler : {$ifdef FPCPROCVAR}@{$endif}pd_virtual;
  1284. pocall : pocall_none;
  1285. pooption : [po_virtualmethod];
  1286. mutexclpocall : [pocall_inline,pocall_internproc];
  1287. mutexclpotype : [];
  1288. mutexclpo : [po_external,po_interrupt,po_exports]
  1289. ),(
  1290. idtok:_CPPDECL;
  1291. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1292. handler : nil;
  1293. pocall : pocall_cppdecl;
  1294. pooption : [po_savestdregs];
  1295. mutexclpocall : [];
  1296. mutexclpotype : [];
  1297. mutexclpo : [po_assembler,po_external]
  1298. ),(
  1299. idtok:_VARARGS;
  1300. pd_flags : pd_interface+pd_implemen+pd_procvar;
  1301. handler : nil;
  1302. pocall : pocall_none;
  1303. pooption : [po_varargs];
  1304. mutexclpocall : [pocall_internproc,pocall_stdcall,pocall_register,
  1305. pocall_inline,pocall_far16,pocall_fpccall];
  1306. mutexclpotype : [];
  1307. mutexclpo : [po_assembler,po_interrupt,po_leftright]
  1308. ),(
  1309. idtok:_COMPILERPROC;
  1310. pd_flags : pd_interface+pd_implemen+pd_body+pd_notobjintf;
  1311. handler : nil;
  1312. pocall : pocall_compilerproc;
  1313. pooption : [];
  1314. mutexclpocall : [];
  1315. mutexclpotype : [];
  1316. mutexclpo : [po_interrupt]
  1317. )
  1318. );
  1319. function is_proc_directive(tok:ttoken):boolean;
  1320. var
  1321. i : longint;
  1322. begin
  1323. is_proc_directive:=false;
  1324. for i:=1 to num_proc_directives do
  1325. if proc_direcdata[i].idtok=idtoken then
  1326. begin
  1327. is_proc_directive:=true;
  1328. exit;
  1329. end;
  1330. end;
  1331. function parse_proc_direc(var pdflags:word):boolean;
  1332. {
  1333. Parse the procedure directive, returns true if a correct directive is found
  1334. }
  1335. var
  1336. p : longint;
  1337. found : boolean;
  1338. name : stringid;
  1339. begin
  1340. parse_proc_direc:=false;
  1341. name:=tokeninfo^[idtoken].str;
  1342. found:=false;
  1343. { Hint directive? Then exit immediatly }
  1344. if (m_hintdirective in aktmodeswitches) then
  1345. begin
  1346. case idtoken of
  1347. _LIBRARY,
  1348. _PLATFORM,
  1349. _DEPRECATED :
  1350. exit;
  1351. end;
  1352. end;
  1353. { retrieve data for directive if found }
  1354. for p:=1 to num_proc_directives do
  1355. if proc_direcdata[p].idtok=idtoken then
  1356. begin
  1357. found:=true;
  1358. break;
  1359. end;
  1360. { Check if the procedure directive is known }
  1361. if not found then
  1362. begin
  1363. { parsing a procvar type the name can be any
  1364. next variable !! }
  1365. if (pdflags and (pd_procvar or pd_object))=0 then
  1366. Message1(parser_w_unknown_proc_directive_ignored,name);
  1367. exit;
  1368. end;
  1369. { static needs a special treatment }
  1370. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1371. exit;
  1372. { Conflicts between directives ? }
  1373. if (aktprocdef.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1374. (aktprocdef.proccalloption in proc_direcdata[p].mutexclpocall) or
  1375. ((aktprocdef.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1376. begin
  1377. Message1(parser_e_proc_dir_conflict,name);
  1378. exit;
  1379. end;
  1380. { set calling convention }
  1381. if proc_direcdata[p].pocall<>pocall_none then
  1382. begin
  1383. if aktprocdef.proccalloption<>pocall_none then
  1384. begin
  1385. Message2(parser_w_proc_overriding_calling,
  1386. proccalloptionStr[aktprocdef.proccalloption],
  1387. proccalloptionStr[proc_direcdata[p].pocall]);
  1388. end;
  1389. aktprocdef.proccalloption:=proc_direcdata[p].pocall;
  1390. end;
  1391. if aktprocdef.deftype=procdef then
  1392. begin
  1393. { Check if the directive is only for objects }
  1394. if ((proc_direcdata[p].pd_flags and pd_object)<>0) and
  1395. not assigned(aktprocdef._class) then
  1396. exit;
  1397. { check if method and directive not for object public }
  1398. if ((proc_direcdata[p].pd_flags and pd_notobject)<>0) and
  1399. assigned(aktprocdef._class) then
  1400. exit;
  1401. { check if method and directive not for interface }
  1402. if ((proc_direcdata[p].pd_flags and pd_notobjintf)<>0) and
  1403. is_interface(aktprocdef._class) then
  1404. exit;
  1405. end;
  1406. { consume directive, and turn flag on }
  1407. consume(token);
  1408. parse_proc_direc:=true;
  1409. { Check the pd_flags if the directive should be allowed }
  1410. if ((pdflags and pd_interface)<>0) and
  1411. ((proc_direcdata[p].pd_flags and pd_interface)=0) then
  1412. begin
  1413. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1414. exit;
  1415. end;
  1416. if ((pdflags and pd_implemen)<>0) and
  1417. ((proc_direcdata[p].pd_flags and pd_implemen)=0) then
  1418. begin
  1419. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1420. exit;
  1421. end;
  1422. if ((pdflags and pd_procvar)<>0) and
  1423. ((proc_direcdata[p].pd_flags and pd_procvar)=0) then
  1424. begin
  1425. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1426. exit;
  1427. end;
  1428. { Return the new pd_flags }
  1429. if (proc_direcdata[p].pd_flags and pd_body)=0 then
  1430. pdflags:=pdflags and (not pd_body);
  1431. if (proc_direcdata[p].pd_flags and pd_global)<>0 then
  1432. pdflags:=pdflags or pd_global;
  1433. { Add the correct flag }
  1434. aktprocdef.procoptions:=aktprocdef.procoptions+proc_direcdata[p].pooption;
  1435. { Call the handler }
  1436. if pointer({$ifndef FPCPROCVAR}@{$endif}proc_direcdata[p].handler)<>nil then
  1437. proc_direcdata[p].handler{$ifdef FPCPROCVAR}(){$endif};
  1438. end;
  1439. procedure handle_calling_convention(sym:tprocsym;def:tabstractprocdef);
  1440. var
  1441. st,parast : tsymtable;
  1442. lastps,ps : tsym;
  1443. begin
  1444. { set the default calling convention }
  1445. if def.proccalloption=pocall_none then
  1446. def.proccalloption:=aktdefproccall;
  1447. case def.proccalloption of
  1448. pocall_cdecl :
  1449. begin
  1450. { use popstack and save std registers }
  1451. include(def.procoptions,po_clearstack);
  1452. include(def.procoptions,po_savestdregs);
  1453. { set mangledname }
  1454. if (def.deftype=procdef) then
  1455. begin
  1456. if not tprocdef(def).has_mangledname then
  1457. tprocdef(def).setmangledname(target_info.Cprefix+sym.realname);
  1458. if not assigned(tprocdef(def).parast) then
  1459. internalerror(200110234);
  1460. { do not copy on local !! }
  1461. tprocdef(def).parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}resetvaluepara);
  1462. { Adjust positions of args for cdecl or stdcall }
  1463. tparasymtable(tprocdef(def).parast).set_alignment(target_info.size_of_longint);
  1464. end;
  1465. end;
  1466. pocall_cppdecl :
  1467. begin
  1468. if not assigned(sym) then
  1469. internalerror(200110231);
  1470. { use popstack and save std registers }
  1471. include(def.procoptions,po_clearstack);
  1472. include(def.procoptions,po_savestdregs);
  1473. { set mangledname }
  1474. if (def.deftype=procdef) then
  1475. begin
  1476. if not tprocdef(def).has_mangledname then
  1477. tprocdef(def).setmangledname(target_info.Cprefix+tprocdef(def).cplusplusmangledname);
  1478. if not assigned(tprocdef(def).parast) then
  1479. internalerror(200110235);
  1480. { do not copy on local !! }
  1481. tprocdef(def).parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}resetvaluepara);
  1482. { Adjust positions of args for cdecl or stdcall }
  1483. tparasymtable(tprocdef(def).parast).set_alignment(target_info.size_of_longint);
  1484. end;
  1485. end;
  1486. pocall_stdcall :
  1487. begin
  1488. include(def.procoptions,po_savestdregs);
  1489. if (def.deftype=procdef) and
  1490. assigned(tprocdef(def).parast) then
  1491. begin
  1492. { Adjust positions of args for cdecl or stdcall }
  1493. tparasymtable(tprocdef(def).parast).set_alignment(target_info.size_of_longint);
  1494. end;
  1495. end;
  1496. pocall_safecall :
  1497. begin
  1498. include(def.procoptions,po_savestdregs);
  1499. end;
  1500. pocall_compilerproc :
  1501. begin
  1502. if (not assigned(sym)) or
  1503. (def.deftype<>procdef) then
  1504. internalerror(200110232);
  1505. tprocdef(def).setmangledname(lower(sym.name));
  1506. end;
  1507. pocall_pascal :
  1508. begin
  1509. include(def.procoptions,po_leftright);
  1510. st:=tparasymtable.create;
  1511. parast:=tprocdef(def).parast;
  1512. lastps:=nil;
  1513. while assigned(parast.symindex.first) and (lastps<>tsym(parast.symindex.first)) do
  1514. begin
  1515. ps:=tsym(parast.symindex.first);
  1516. while assigned(ps.indexnext) and (tsym(ps.indexnext)<>lastps) do
  1517. ps:=tsym(ps.indexnext);
  1518. ps.owner:=st;
  1519. { recalculate the corrected offset }
  1520. { the really_insert_in_data procedure
  1521. for parasymtable should only calculateoffset PM }
  1522. tstoredsym(ps).insert_in_data;
  1523. { reset the owner correctly }
  1524. ps.owner:=parast;
  1525. lastps:=ps;
  1526. end;
  1527. end;
  1528. pocall_register :
  1529. begin
  1530. Message1(parser_w_proc_directive_ignored,'REGISTER');
  1531. end;
  1532. pocall_far16 :
  1533. begin
  1534. { Temporary stub, must be rewritten to support OS/2 far16 }
  1535. Message1(parser_w_proc_directive_ignored,'FAR16');
  1536. end;
  1537. pocall_system :
  1538. begin
  1539. include(def.procoptions,po_clearstack);
  1540. if (not assigned(sym)) or
  1541. (def.deftype<>procdef) then
  1542. internalerror(200110233);
  1543. if not tprocdef(def).has_mangledname then
  1544. tprocdef(def).setmangledname(sym.realname);
  1545. end;
  1546. pocall_palmossyscall :
  1547. begin
  1548. { use popstack and save std registers }
  1549. include(def.procoptions,po_clearstack);
  1550. include(def.procoptions,po_savestdregs);
  1551. if (def.deftype=procdef) then
  1552. begin
  1553. if not assigned(tprocdef(def).parast) then
  1554. internalerror(200110236);
  1555. { do not copy on local !! }
  1556. tprocdef(def).parast.foreach_static({$ifdef FPCPROCVAR}@{$endif}resetvaluepara);
  1557. { Adjust positions of args for cdecl or stdcall }
  1558. tparasymtable(tprocdef(def).parast).set_alignment(target_info.size_of_longint);
  1559. end;
  1560. end;
  1561. pocall_inline :
  1562. begin
  1563. if not(cs_support_inline in aktmoduleswitches) then
  1564. begin
  1565. Message(parser_e_proc_inline_not_supported);
  1566. def.proccalloption:=pocall_fpccall;
  1567. end;
  1568. end;
  1569. end;
  1570. { add mangledname to external list }
  1571. if (def.deftype=procdef) and
  1572. (po_external in def.procoptions) and
  1573. target_info.DllScanSupported then
  1574. current_module.externals.insert(tExternalsItem.create(tprocdef(def).mangledname));
  1575. end;
  1576. procedure parse_proc_directives(var pdflags:word);
  1577. {
  1578. Parse the procedure directives. It does not matter if procedure directives
  1579. are written using ;procdir; or ['procdir'] syntax.
  1580. }
  1581. var
  1582. res : boolean;
  1583. begin
  1584. while token in [_ID,_LECKKLAMMER] do
  1585. begin
  1586. if try_to_consume(_LECKKLAMMER) then
  1587. begin
  1588. repeat
  1589. parse_proc_direc(pdflags);
  1590. until not try_to_consume(_COMMA);
  1591. consume(_RECKKLAMMER);
  1592. { we always expect at least '[];' }
  1593. res:=true;
  1594. end
  1595. else
  1596. begin
  1597. res:=parse_proc_direc(pdflags);
  1598. end;
  1599. { A procedure directive normally followed by a semicolon, but in
  1600. a const section we should stop when _EQUAL is found }
  1601. if res then
  1602. begin
  1603. if (block_type=bt_const) and
  1604. (token=_EQUAL) then
  1605. break;
  1606. { support procedure proc;stdcall export; in Delphi mode only }
  1607. if not((m_delphi in aktmodeswitches) and
  1608. is_proc_directive(token)) then
  1609. consume(_SEMICOLON);
  1610. end
  1611. else
  1612. break;
  1613. end;
  1614. handle_calling_convention(aktprocsym,aktprocdef);
  1615. end;
  1616. procedure parse_var_proc_directives(var sym : tsym);
  1617. var
  1618. pdflags : word;
  1619. oldsym : tprocsym;
  1620. olddef : tprocdef;
  1621. pd : tabstractprocdef;
  1622. begin
  1623. oldsym:=aktprocsym;
  1624. olddef:=aktprocdef;
  1625. pdflags:=pd_procvar;
  1626. { we create a temporary aktprocsym to read the directives }
  1627. aktprocsym:=tprocsym.create(sym.name);
  1628. case sym.typ of
  1629. varsym :
  1630. pd:=tabstractprocdef(tvarsym(sym).vartype.def);
  1631. typedconstsym :
  1632. pd:=tabstractprocdef(ttypedconstsym(sym).typedconsttype.def);
  1633. typesym :
  1634. pd:=tabstractprocdef(ttypesym(sym).restype.def);
  1635. else
  1636. internalerror(994932432);
  1637. end;
  1638. if pd.deftype<>procvardef then
  1639. internalerror(994932433);
  1640. tabstractprocdef(aktprocdef):=pd;
  1641. { names should never be used anyway }
  1642. inc(lexlevel);
  1643. parse_proc_directives(pdflags);
  1644. dec(lexlevel);
  1645. aktprocsym.free;
  1646. aktprocsym:=oldsym;
  1647. aktprocdef:=olddef;
  1648. end;
  1649. procedure parse_object_proc_directives(var sym : tprocsym);
  1650. var
  1651. pdflags : word;
  1652. begin
  1653. pdflags:=pd_object;
  1654. inc(lexlevel);
  1655. parse_proc_directives(pdflags);
  1656. dec(lexlevel);
  1657. if (po_containsself in aktprocdef.procoptions) and
  1658. (([po_msgstr,po_msgint]*aktprocdef.procoptions)=[]) then
  1659. Message(parser_e_self_in_non_message_handler);
  1660. end;
  1661. function proc_add_definition(aprocsym:tprocsym;var aprocdef : tprocdef) : boolean;
  1662. {
  1663. Add definition aprocdef to the overloaded definitions of aprocsym. If a
  1664. forwarddef is found and reused it returns true
  1665. }
  1666. var
  1667. hd : tprocdef;
  1668. pdl : pprocdeflist;
  1669. ad,fd : tsym;
  1670. forwardfound : boolean;
  1671. begin
  1672. forwardfound:=false;
  1673. { check overloaded functions if the same function already exists }
  1674. pdl:=aprocsym.defs;
  1675. while assigned(pdl) do
  1676. begin
  1677. hd:=pdl^.def;
  1678. { check the parameters, for delphi/tp it is possible to
  1679. leave the parameters away in the implementation (forwarddef=false).
  1680. But for an overload declared function this is not allowed }
  1681. if { check if empty implementation arguments match is allowed }
  1682. (
  1683. not(m_repeat_forward in aktmodeswitches) and
  1684. not(aprocdef.forwarddef) and
  1685. (aprocdef.maxparacount=0) and
  1686. not(po_overload in hd.procoptions)
  1687. ) or
  1688. { check arguments }
  1689. (
  1690. equal_paras(aprocdef.para,hd.para,cp_none) and
  1691. { for operators equal_paras is not enough !! }
  1692. ((aprocdef.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  1693. is_equal(hd.rettype.def,aprocdef.rettype.def))
  1694. ) then
  1695. begin
  1696. { Check if we've found the forwarddef, if found then
  1697. we need to update the forward def with the current
  1698. implementation settings }
  1699. if hd.forwarddef then
  1700. begin
  1701. { Check if the procedure type and return type are correct }
  1702. if (hd.proctypeoption<>aprocdef.proctypeoption) or
  1703. (not(is_equal(hd.rettype.def,aprocdef.rettype.def)) and
  1704. (m_repeat_forward in aktmodeswitches)) then
  1705. begin
  1706. MessagePos1(aprocdef.fileinfo,parser_e_header_dont_match_forward,
  1707. aprocdef.fullprocname);
  1708. break;
  1709. end;
  1710. { Check if both are declared forward }
  1711. if hd.forwarddef and aprocdef.forwarddef then
  1712. begin
  1713. MessagePos1(aprocdef.fileinfo,parser_e_function_already_declared_public_forward,
  1714. aprocdef.fullprocname);
  1715. end;
  1716. { internconst or internproc only need to be defined once }
  1717. if (hd.proccalloption in [pocall_internconst,pocall_internproc]) then
  1718. aprocdef.proccalloption:=hd.proccalloption
  1719. else
  1720. if (aprocdef.proccalloption in [pocall_internconst,pocall_internproc]) then
  1721. hd.proccalloption:=aprocdef.proccalloption;
  1722. { Check calling convention }
  1723. if (hd.proccalloption<>aprocdef.proccalloption) then
  1724. begin
  1725. { For delphi check if the current implementation has no proccalloption, then
  1726. take the options from the interface }
  1727. if (m_delphi in aktmodeswitches) then
  1728. begin
  1729. if (aprocdef.proccalloption=pocall_none) then
  1730. aprocdef.proccalloption:=hd.proccalloption
  1731. else
  1732. MessagePos(aprocdef.fileinfo,parser_e_call_convention_dont_match_forward);
  1733. end
  1734. else
  1735. MessagePos(aprocdef.fileinfo,parser_e_call_convention_dont_match_forward);
  1736. { restore interface settings for error recovery }
  1737. aprocdef.proccalloption:=hd.proccalloption;
  1738. aprocdef.setmangledname(hd.mangledname);
  1739. end;
  1740. { Check manglednames }
  1741. hd.count:=false;
  1742. if (m_repeat_forward in aktmodeswitches) or
  1743. aprocdef.haspara then
  1744. begin
  1745. if (hd.mangledname<>aprocdef.mangledname) then
  1746. begin
  1747. if not(po_external in aprocdef.procoptions) then
  1748. MessagePos2(aprocdef.fileinfo,parser_n_interface_name_diff_implementation_name,
  1749. hd.mangledname,aprocdef.mangledname);
  1750. { if the mangledname is already used, then rename it to the
  1751. new mangledname of the implementation }
  1752. if hd.is_used then
  1753. renameasmsymbol(hd.mangledname,aprocdef.mangledname);
  1754. { reset the mangledname of the interface }
  1755. hd.setmangledname(aprocdef.mangledname);
  1756. end
  1757. else
  1758. begin
  1759. { If mangled names are equal then they have the same amount of arguments }
  1760. { We can check the names of the arguments }
  1761. { both symtables are in the same order from left to right }
  1762. ad:=tsym(hd.parast.symindex.first);
  1763. fd:=tsym(aprocdef.parast.symindex.first);
  1764. while assigned(ad) and assigned(fd) do
  1765. begin
  1766. if ad.name<>fd.name then
  1767. begin
  1768. { don't give an error if the default parameter is not
  1769. specified in the implementation }
  1770. if ((copy(fd.name,1,3)='def') and
  1771. (copy(ad.name,1,3)<>'def')) then
  1772. MessagePos3(aprocdef.fileinfo,parser_e_header_different_var_names,
  1773. aprocsym.name,ad.name,fd.name);
  1774. break;
  1775. end;
  1776. ad:=tsym(ad.indexnext);
  1777. fd:=tsym(fd.indexnext);
  1778. end;
  1779. end;
  1780. end;
  1781. hd.count:=true;
  1782. { Everything is checked, now we can update the forward declaration
  1783. with the new data from the implementation }
  1784. hd.forwarddef:=aprocdef.forwarddef;
  1785. hd.hasforward:=true;
  1786. hd.parast.address_fixup:=aprocdef.parast.address_fixup;
  1787. hd.procoptions:=hd.procoptions+aprocdef.procoptions;
  1788. if hd.extnumber=-1 then
  1789. hd.extnumber:=aprocdef.extnumber;
  1790. while not aprocdef.aliasnames.empty do
  1791. hd.aliasnames.insert(aprocdef.aliasnames.getfirst);
  1792. { for compilerproc defines we need to rename and update the
  1793. symbolname to lowercase }
  1794. if (aprocdef.proccalloption=pocall_compilerproc) then
  1795. begin
  1796. { rename to lowercase so users can't access it }
  1797. aprocsym.owner.rename(aprocsym.name,lower(aprocsym.name));
  1798. { also update the realname that is stored in the ppu }
  1799. stringdispose(aprocsym._realname);
  1800. aprocsym._realname:=stringdup('$'+aprocsym.name);
  1801. { the mangeled name is already changed by the pd_compilerproc }
  1802. { handler. It must be done immediately because if we have a }
  1803. { call to a compilerproc before it's implementation is }
  1804. { encountered, it must already use the new mangled name (JM) }
  1805. end;
  1806. { return the forwarddef }
  1807. aprocdef:=hd;
  1808. forwardfound:=true;
  1809. end
  1810. else
  1811. begin
  1812. { abstract methods aren't forward defined, but this }
  1813. { needs another error message }
  1814. if (po_abstractmethod in hd.procoptions) then
  1815. MessagePos(aprocdef.fileinfo,parser_e_abstract_no_definition)
  1816. else
  1817. MessagePos(aprocdef.fileinfo,parser_e_overloaded_have_same_parameters);
  1818. end;
  1819. { we found one proc with the same arguments, there are no others
  1820. so we can stop }
  1821. break;
  1822. end;
  1823. { check for allowing overload directive }
  1824. if not(m_fpc in aktmodeswitches) then
  1825. begin
  1826. { overload directive turns on overloading }
  1827. if ((po_overload in aprocdef.procoptions) or
  1828. (po_overload in hd.procoptions)) then
  1829. begin
  1830. { check if all procs have overloading, but not if the proc was
  1831. already declared forward, then the check is already done }
  1832. if not(hd.hasforward or
  1833. (aprocdef.forwarddef<>hd.forwarddef) or
  1834. ((po_overload in aprocdef.procoptions) and
  1835. (po_overload in hd.procoptions))) then
  1836. begin
  1837. MessagePos1(aprocdef.fileinfo,parser_e_no_overload_for_all_procs,aprocsym.realname);
  1838. break;
  1839. end;
  1840. end
  1841. else
  1842. begin
  1843. if not(hd.forwarddef) then
  1844. begin
  1845. MessagePos(aprocdef.fileinfo,parser_e_procedure_overloading_is_off);
  1846. break;
  1847. end;
  1848. end;
  1849. end; { equal arguments }
  1850. { try next overloaded }
  1851. pdl:=pdl^.next;
  1852. end;
  1853. { if we didn't reuse a forwarddef then we add the procdef to the overloaded
  1854. list }
  1855. if not forwardfound then
  1856. aprocsym.addprocdef(aprocdef);
  1857. { insert otsym only in the right symtable }
  1858. if ((procinfo^.flags and pi_operator)<>0) and
  1859. assigned(otsym) and
  1860. not parse_only then
  1861. begin
  1862. if ret_in_param(aprocdef.rettype.def) then
  1863. begin
  1864. aprocdef.parast.insert(otsym);
  1865. { this increases the data size }
  1866. { correct this to get the right ret $value }
  1867. dec(aprocdef.parast.datasize,
  1868. align(otsym.getpushsize,aktprocdef.parast.dataalignment));
  1869. { this allows to read the funcretoffset }
  1870. otsym.address:=-4;
  1871. otsym.varspez:=vs_var;
  1872. end
  1873. else
  1874. aprocdef.localst.insert(otsym);
  1875. end;
  1876. proc_add_definition:=forwardfound;
  1877. end;
  1878. end.
  1879. {
  1880. $Log$
  1881. Revision 1.41 2001-11-02 22:58:03 peter
  1882. * procsym definition rewrite
  1883. Revision 1.40 2001/10/25 21:22:37 peter
  1884. * calling convention rewrite
  1885. Revision 1.39 2001/10/23 21:49:42 peter
  1886. * $calling directive and -Cc commandline patch added
  1887. from Pavel Ozerski
  1888. Revision 1.38 2001/10/01 13:38:44 jonas
  1889. * allow self parameter for normal procedures again (because Kylix allows
  1890. it too) ("merged")
  1891. Revision 1.37 2001/09/10 10:26:26 jonas
  1892. * fixed web bug 1593
  1893. * writing of procvar headers is more complete (mention var/const/out for
  1894. paras, add "of object" if applicable)
  1895. + error if declaring explicit self para as var/const
  1896. * fixed mangled name of procedures which contain an explicit self para
  1897. * parsing para's should be slightly faster because mangled name of
  1898. procedure is only updated once instead of after parsing each para
  1899. (all merged from fixes)
  1900. Revision 1.36 2001/08/26 13:36:45 florian
  1901. * some cg reorganisation
  1902. * some PPC updates
  1903. Revision 1.35 2001/08/23 14:28:36 jonas
  1904. + tempcreate/ref/delete nodes (allows the use of temps in the
  1905. resulttype and first pass)
  1906. * made handling of read(ln)/write(ln) processor independent
  1907. * moved processor independent handling for str and reset/rewrite-typed
  1908. from firstpass to resulttype pass
  1909. * changed names of helpers in text.inc to be generic for use as
  1910. compilerprocs + added "iocheck" directive for most of them
  1911. * reading of ordinals is done by procedures instead of functions
  1912. because otherwise FPC_IOCHECK overwrote the result before it could
  1913. be stored elsewhere (range checking still works)
  1914. * compilerprocs can now be used in the system unit before they are
  1915. implemented
  1916. * added note to errore.msg that booleans can't be read using read/readln
  1917. Revision 1.34 2001/08/22 21:16:21 florian
  1918. * some interfaces related problems regarding
  1919. mapping of interface implementions fixed
  1920. Revision 1.33 2001/08/19 21:11:20 florian
  1921. * some bugs fix:
  1922. - overload; with external procedures fixed
  1923. - better selection of routine to do an overloaded
  1924. type case
  1925. - ... some more
  1926. Revision 1.32 2001/08/19 11:22:23 peter
  1927. * palmos support from v10 merged
  1928. Revision 1.31 2001/08/05 13:18:50 peter
  1929. * turn pocall_inline off when inline is not supported
  1930. Revision 1.30 2001/08/01 15:07:29 jonas
  1931. + "compilerproc" directive support, which turns both the public and mangled
  1932. name to lowercase(declaration_name). This prevents a normal user from
  1933. accessing the routine, but they can still be easily looked up within
  1934. the compiler. This is used for helper procedures and should facilitate
  1935. the writing of more processor independent code in the code generator
  1936. itself (mostly written by Peter)
  1937. + new "createintern" constructor for tcal nodes to create a call to
  1938. helper exported using the "compilerproc" directive
  1939. + support for high(dynamic_array) using the the above new things
  1940. + definition of 'HASCOMPILERPROC' symbol (to be able to check in the
  1941. compiler and rtl whether the "compilerproc" directive is supported)
  1942. Revision 1.29 2001/07/09 21:11:14 peter
  1943. * fixed overload checking for delphi. Empty parameters are only
  1944. allowed in implementation and not when the forward declaration
  1945. contains overload directive
  1946. Revision 1.28 2001/07/01 20:16:16 peter
  1947. * alignmentinfo record added
  1948. * -Oa argument supports more alignment settings that can be specified
  1949. per type: PROC,LOOP,VARMIN,VARMAX,CONSTMIN,CONSTMAX,RECORDMIN
  1950. RECORDMAX,LOCALMIN,LOCALMAX. It is possible to set the mimimum
  1951. required alignment and the maximum usefull alignment. The final
  1952. alignment will be choosen per variable size dependent on these
  1953. settings
  1954. Revision 1.27 2001/06/04 18:12:26 peter
  1955. * fixed crash with procvar directive parsing. Be carefull as the procvar
  1956. directive parsing uses aktprocdef that is a tprocdef, but
  1957. for procvar the type is tprocvardef. So some fields are not available
  1958. Revision 1.26 2001/06/04 11:53:13 peter
  1959. + varargs directive
  1960. Revision 1.25 2001/06/03 21:57:36 peter
  1961. + hint directive parsing support
  1962. Revision 1.24 2001/05/08 21:06:31 florian
  1963. * some more support for widechars commited especially
  1964. regarding type casting and constants
  1965. Revision 1.23 2001/05/08 14:32:58 jonas
  1966. * fixed bug for overloaded operators with a return type that has a size
  1967. which isn't a multiple of the target_os.stackalignment (main branch
  1968. patch from Peter)
  1969. Revision 1.22 2001/05/04 15:52:03 florian
  1970. * some Delphi incompatibilities fixed:
  1971. - out, dispose and new can be used as idenfiers now
  1972. - const p = apointerype(nil); is supported now
  1973. + support for const p = apointertype(pointer(1234)); added
  1974. Revision 1.21 2001/04/18 22:01:57 peter
  1975. * registration of targets and assemblers
  1976. Revision 1.20 2001/04/13 20:05:16 peter
  1977. * better check for globalsymtable
  1978. Revision 1.19 2001/04/13 18:03:16 peter
  1979. * give error with local external procedure
  1980. Revision 1.18 2001/04/13 01:22:11 peter
  1981. * symtable change to classes
  1982. * range check generation and errors fixed, make cycle DEBUG=1 works
  1983. * memory leaks fixed
  1984. Revision 1.17 2001/04/04 22:43:52 peter
  1985. * remove unnecessary calls to firstpass
  1986. Revision 1.16 2001/04/02 21:20:33 peter
  1987. * resulttype rewrite
  1988. Revision 1.15 2001/03/24 12:18:11 florian
  1989. * procedure p(); is now allowed in all modes except TP
  1990. Revision 1.14 2001/03/22 22:35:42 florian
  1991. + support for type a = (a=1); in Delphi mode added
  1992. + procedure p(); in Delphi mode supported
  1993. + on isn't keyword anymore, it can be used as
  1994. id etc. now
  1995. Revision 1.13 2001/03/11 22:58:50 peter
  1996. * getsym redesign, removed the globals srsym,srsymtable
  1997. Revision 1.12 2001/03/06 18:28:02 peter
  1998. * patch from Pavel with a new and much faster DLL Scanner for
  1999. automatic importing so $linklib works for DLLs. Thanks Pavel!
  2000. Revision 1.11 2001/01/08 21:40:26 peter
  2001. * fixed crash with unsupported token overloading
  2002. Revision 1.10 2000/12/25 00:07:27 peter
  2003. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  2004. tlinkedlist objects)
  2005. Revision 1.9 2000/11/29 00:30:35 florian
  2006. * unused units removed from uses clause
  2007. * some changes for widestrings
  2008. Revision 1.8 2000/11/26 23:45:34 florian
  2009. * pascal modifier in interfaces of units works now
  2010. Revision 1.7 2000/11/06 20:30:55 peter
  2011. * more fixes to get make cycle working
  2012. Revision 1.6 2000/11/04 14:25:20 florian
  2013. + merged Attila's changes for interfaces, not tested yet
  2014. Revision 1.5 2000/11/01 23:04:37 peter
  2015. * tprocdef.fullprocname added for better casesensitve writing of
  2016. procedures
  2017. Revision 1.4 2000/10/31 22:02:49 peter
  2018. * symtable splitted, no real code changes
  2019. Revision 1.3 2000/10/21 18:16:11 florian
  2020. * a lot of changes:
  2021. - basic dyn. array support
  2022. - basic C++ support
  2023. - some work for interfaces done
  2024. ....
  2025. Revision 1.2 2000/10/15 07:47:51 peter
  2026. * unit names and procedure names are stored mixed case
  2027. Revision 1.1 2000/10/14 10:14:51 peter
  2028. * moehrendorf oct 2000 rewrite
  2029. }