pdecsub.pas 77 KB

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