pdecsub.pas 68 KB

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