psub.pas 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733
  1. {
  2. $Id$
  3. Copyright (c) 1998 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 psub;
  19. interface
  20. uses
  21. cobjects,
  22. symconst,symtable;
  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. procedure compile_proc_body(const proc_names:Tstringcontainer;
  32. make_global,parent_has_class:boolean);
  33. procedure parse_proc_head(options:tproctypeoption);
  34. procedure parse_proc_dec;
  35. procedure parse_var_proc_directives(var sym : ptypesym);
  36. procedure parse_object_proc_directives(var sym : pprocsym);
  37. procedure read_proc;
  38. implementation
  39. uses
  40. globtype,systems,tokens,
  41. strings,globals,verbose,files,
  42. scanner,aasm,tree,types,
  43. import,gendef,
  44. hcodegen,temp_gen,pass_1,cpubase,cpuasm
  45. {$ifndef NOPASS2}
  46. ,pass_2
  47. {$endif}
  48. {$ifdef GDB}
  49. ,gdb
  50. {$endif GDB}
  51. {$ifdef i386}
  52. ,tgeni386
  53. {$ifndef newcg}
  54. ,cgai386
  55. {$endif newcg}
  56. {$ifndef NoOpt}
  57. ,aopt386
  58. {$endif}
  59. {$endif}
  60. {$ifdef m68k}
  61. ,tgen68k,cga68k
  62. {$endif}
  63. { parser specific stuff }
  64. ,pbase,pdecl,pexpr,pstatmnt
  65. {$ifdef newcg}
  66. ,tgcpu,convtree,cgobj,tgeni386 { for the new code generator tgeni386 is only a dummy }
  67. {$endif newcg}
  68. ;
  69. var
  70. realname:string; { contains the real name of a procedure as it's typed }
  71. procedure formal_parameter_list;
  72. {
  73. handle_procvar needs the same changes
  74. }
  75. var
  76. sc : Pstringcontainer;
  77. s : string;
  78. storetokenpos : tfileposinfo;
  79. p : Pdef;
  80. hsym : psym;
  81. hvs,
  82. vs : Pvarsym;
  83. hs1,hs2 : string;
  84. varspez : Tvarspez;
  85. inserthigh : boolean;
  86. begin
  87. consume(_LKLAMMER);
  88. inc(testcurobject);
  89. repeat
  90. if try_to_consume(_VAR) then
  91. varspez:=vs_var
  92. else
  93. if try_to_consume(_CONST) then
  94. varspez:=vs_const
  95. else
  96. varspez:=vs_value;
  97. inserthigh:=false;
  98. readtypesym:=nil;
  99. if idtoken=_SELF then
  100. begin
  101. { we parse the defintion in the class definition }
  102. if assigned(procinfo._class) and procinfo._class^.is_class then
  103. begin
  104. {$ifndef UseNiceNames}
  105. hs2:=hs2+'$'+'self';
  106. {$else UseNiceNames}
  107. hs2:=hs2+tostr(length('self'))+'self';
  108. {$endif UseNiceNames}
  109. vs:=new(Pvarsym,init('@',procinfo._class));
  110. vs^.varspez:=vs_var;
  111. { insert the sym in the parasymtable }
  112. aktprocsym^.definition^.parast^.insert(vs);
  113. {$ifdef INCLUDEOK}
  114. include(aktprocsym^.definition^.procoptions,po_containsself);
  115. {$else}
  116. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_containsself];
  117. {$endif}
  118. inc(procinfo.ESI_offset,vs^.address);
  119. consume(idtoken);
  120. consume(_COLON);
  121. p:=single_type(hs1);
  122. if assigned(readtypesym) then
  123. aktprocsym^.definition^.concattypesym(readtypesym,vs_value)
  124. else
  125. aktprocsym^.definition^.concatdef(p,vs_value);
  126. CheckTypes(p,procinfo._class);
  127. end
  128. else
  129. consume(_ID);
  130. end
  131. else
  132. begin
  133. { read identifiers }
  134. sc:=idlist;
  135. { read type declaration, force reading for value and const paras }
  136. if (token=_COLON) or (varspez=vs_value) then
  137. begin
  138. consume(_COLON);
  139. { check for an open array }
  140. if token=_ARRAY then
  141. begin
  142. consume(_ARRAY);
  143. consume(_OF);
  144. { define range and type of range }
  145. p:=new(Parraydef,init(0,-1,s32bitdef));
  146. { array of const ? }
  147. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  148. begin
  149. consume(_CONST);
  150. srsym:=nil;
  151. if assigned(objpasunit) then
  152. getsymonlyin(objpasunit,'TVARREC');
  153. if not assigned(srsym) then
  154. InternalError(1234124);
  155. Parraydef(p)^.definition:=ptypesym(srsym)^.definition;
  156. Parraydef(p)^.IsArrayOfConst:=true;
  157. hs1:='array_of_const';
  158. end
  159. else
  160. begin
  161. { define field type }
  162. Parraydef(p)^.definition:=single_type(hs1);
  163. hs1:='array_of_'+hs1;
  164. { we don't need the typesym anymore }
  165. readtypesym:=nil;
  166. end;
  167. inserthigh:=true;
  168. end
  169. { open string ? }
  170. else if (varspez=vs_var) and
  171. (
  172. (
  173. ((token=_STRING) or (idtoken=_SHORTSTRING)) and
  174. (cs_openstring in aktmoduleswitches) and
  175. not(cs_ansistrings in aktlocalswitches)
  176. ) or
  177. (idtoken=_OPENSTRING)) then
  178. begin
  179. consume(token);
  180. p:=openshortstringdef;
  181. hs1:='openstring';
  182. inserthigh:=true;
  183. end
  184. { everything else }
  185. else
  186. p:=single_type(hs1);
  187. end
  188. else
  189. begin
  190. {$ifndef UseNiceNames}
  191. hs1:='$$$';
  192. {$else UseNiceNames}
  193. hs1:='var';
  194. {$endif UseNiceNames}
  195. p:=cformaldef;
  196. { }
  197. end;
  198. hs2:=aktprocsym^.definition^.mangledname;
  199. storetokenpos:=tokenpos;
  200. while not sc^.empty do
  201. begin
  202. {$ifndef UseNiceNames}
  203. hs2:=hs2+'$'+hs1;
  204. {$else UseNiceNames}
  205. hs2:=hs2+tostr(length(hs1))+hs1;
  206. {$endif UseNiceNames}
  207. s:=sc^.get_with_tokeninfo(tokenpos);
  208. if assigned(readtypesym) then
  209. begin
  210. aktprocsym^.definition^.concattypesym(readtypesym,varspez);
  211. vs:=new(Pvarsym,initsym(s,readtypesym))
  212. end
  213. else
  214. begin
  215. aktprocsym^.definition^.concatdef(p,varspez);
  216. vs:=new(Pvarsym,init(s,p));
  217. end;
  218. vs^.varspez:=varspez;
  219. { we have to add this to avoid var param to be in registers !!!}
  220. if (varspez in [vs_var,vs_const]) and push_addr_param(p) then
  221. {$ifdef INCLUDEOK}
  222. include(vs^.varoptions,vo_regable);
  223. {$else}
  224. vs^.varoptions:=vs^.varoptions+[vo_regable];
  225. {$endif}
  226. { search for duplicate ids in object members/methods }
  227. { but only the current class, I don't know why ... }
  228. { at least TP and Delphi do it in that way (FK) }
  229. if assigned(procinfo._class) and
  230. (lexlevel=normal_function_level) then
  231. begin
  232. hsym:=procinfo._class^.symtable^.search(vs^.name);
  233. if assigned(hsym) then
  234. DuplicateSym(hsym);
  235. end;
  236. { do we need a local copy }
  237. if (varspez=vs_value) and push_addr_param(p) and
  238. not(is_open_array(p) or is_array_of_const(p)) then
  239. vs^.setname('val'+vs^.name);
  240. { insert the sym in the parasymtable }
  241. aktprocsym^.definition^.parast^.insert(vs);
  242. { also need to push a high value? }
  243. if inserthigh then
  244. begin
  245. hvs:=new(Pvarsym,init('high'+s,s32bitdef));
  246. hvs^.varspez:=vs_const;
  247. aktprocsym^.definition^.parast^.insert(hvs);
  248. end;
  249. end;
  250. dispose(sc,done);
  251. tokenpos:=storetokenpos;
  252. end;
  253. aktprocsym^.definition^.setmangledname(hs2);
  254. until not try_to_consume(_SEMICOLON);
  255. dec(testcurobject);
  256. consume(_RKLAMMER);
  257. end;
  258. procedure parse_proc_head(options:tproctypeoption);
  259. var sp:stringid;
  260. pd:Pprocdef;
  261. paramoffset:longint;
  262. sym:Psym;
  263. hs:string;
  264. st : psymtable;
  265. overloaded_level:word;
  266. procstartfilepos : tfileposinfo;
  267. begin
  268. { Save the position where this procedure really starts and set col to 1 which
  269. looks nicer }
  270. procstartfilepos:=aktfilepos;
  271. procstartfilepos.column:=1;
  272. if (options=potype_operator) then
  273. begin
  274. sp:=overloaded_names[optoken];
  275. realname:=sp;
  276. end
  277. else
  278. begin
  279. sp:=pattern;
  280. realname:=orgpattern;
  281. consume(_ID);
  282. end;
  283. { method ? }
  284. if not(parse_only) and try_to_consume(_POINT) then
  285. begin
  286. getsym(sp,true);
  287. sym:=srsym;
  288. { qualifier is class name ? }
  289. if (sym^.typ<>typesym) or
  290. (ptypesym(sym)^.definition^.deftype<>objectdef) then
  291. begin
  292. Message(parser_e_class_id_expected);
  293. aktprocsym:=nil;
  294. consume(_ID);
  295. end
  296. else
  297. begin
  298. { used to allow private syms to be seen }
  299. aktobjectdef:=pobjectdef(ptypesym(sym)^.definition);
  300. sp:=pattern;
  301. realname:=orgpattern;
  302. consume(_ID);
  303. procinfo._class:=pobjectdef(ptypesym(sym)^.definition);
  304. aktprocsym:=pprocsym(procinfo._class^.symtable^.search(sp));
  305. aktobjectdef:=nil;
  306. { we solve this below }
  307. if not(assigned(aktprocsym)) then
  308. Message(parser_e_methode_id_expected);
  309. end;
  310. end
  311. else
  312. begin
  313. { check for constructor/destructor which is not allowed here }
  314. if (not parse_only) and
  315. (options in [potype_constructor,potype_destructor]) then
  316. Message(parser_e_constructors_always_objects);
  317. aktprocsym:=pprocsym(symtablestack^.search(sp));
  318. if lexlevel=normal_function_level then
  319. {$ifdef UseNiceNames}
  320. hs:=procprefix+'_'+tostr(length(sp))+sp
  321. {$else UseNiceNames}
  322. hs:=procprefix+'_'+sp
  323. {$endif UseNiceNames}
  324. else
  325. {$ifdef UseNiceNames}
  326. hs:=lowercase(procprefix)+'_'+tostr(length(sp))+sp;
  327. {$else UseNiceNames}
  328. hs:=procprefix+'_$'+sp;
  329. {$endif UseNiceNames}
  330. if not(parse_only) then
  331. begin
  332. {The procedure we prepare for is in the implementation
  333. part of the unit we compile. It is also possible that we
  334. are compiling a program, which is also some kind of
  335. implementaion part.
  336. We need to find out if the procedure is global. If it is
  337. global, it is in the global symtable.}
  338. if not assigned(aktprocsym) then
  339. begin
  340. {Search the procedure in the global symtable.}
  341. aktprocsym:=Pprocsym(search_a_symtable(sp,globalsymtable));
  342. if assigned(aktprocsym) then
  343. begin
  344. {Check if it is a procedure.}
  345. if aktprocsym^.typ<>procsym then
  346. DuplicateSym(aktprocsym);
  347. {The procedure has been found. So it is
  348. a global one. Set the flags to mark this.}
  349. procinfo.flags:=procinfo.flags or pi_is_global;
  350. end;
  351. end;
  352. end;
  353. end;
  354. { problem with procedures inside methods }
  355. {$ifndef UseNiceNames}
  356. if assigned(procinfo._class) then
  357. if (pos('_$$_',procprefix)=0) then
  358. hs:=procprefix+'_$$_'+procinfo._class^.objname^+'_$$_'+sp
  359. else
  360. hs:=procprefix+'_$'+sp;
  361. {$else UseNiceNames}
  362. if assigned(procinfo._class) then
  363. if (pos('_5Class_',procprefix)=0) then
  364. hs:=procprefix+'_5Class_'+procinfo._class^.name^+'_'+tostr(length(sp))+sp
  365. else
  366. hs:=procprefix+'_'+tostr(length(sp))+sp;
  367. {$endif UseNiceNames}
  368. if assigned(aktprocsym) then
  369. begin
  370. { Check if overloading is enabled }
  371. if not(m_fpc in aktmodeswitches) then
  372. begin
  373. if aktprocsym^.typ<>procsym then
  374. begin
  375. DuplicateSym(aktprocsym);
  376. { try to recover by creating a new aktprocsym }
  377. aktprocsym:=new(pprocsym,init(sp));
  378. end
  379. else
  380. begin
  381. if not(aktprocsym^.definition^.forwarddef) then
  382. Message(parser_e_procedure_overloading_is_off);
  383. end;
  384. end
  385. else
  386. begin
  387. { Check if the overloaded sym is realy a procsym }
  388. if aktprocsym^.typ<>procsym then
  389. begin
  390. Message1(parser_e_overloaded_no_procedure,aktprocsym^.name);
  391. { try to recover by creating a new aktprocsym }
  392. aktprocsym:=new(pprocsym,init(sp));
  393. end;
  394. end;
  395. end
  396. else
  397. begin
  398. { create a new procsym and set the real filepos }
  399. aktprocsym:=new(pprocsym,init(sp));
  400. { for operator we have only one definition for each overloaded
  401. operation }
  402. if (options=potype_operator) then
  403. begin
  404. { the only problem is that nextoverloaded might not be in a unit
  405. known for the unit itself }
  406. if assigned(overloaded_operators[optoken]) then
  407. aktprocsym^.definition:=overloaded_operators[optoken]^.definition;
  408. end;
  409. symtablestack^.insert(aktprocsym);
  410. end;
  411. st:=symtablestack;
  412. pd:=new(pprocdef,init);
  413. pd^.symtablelevel:=symtablestack^.symtablelevel;
  414. if assigned(procinfo._class) then
  415. pd^._class := procinfo._class;
  416. { set the options from the caller (podestructor or poconstructor) }
  417. pd^.proctypeoption:=options;
  418. { calculate the offset of the parameters }
  419. paramoffset:=8;
  420. { calculate frame pointer offset }
  421. if lexlevel>normal_function_level then
  422. begin
  423. procinfo.framepointer_offset:=paramoffset;
  424. inc(paramoffset,target_os.size_of_pointer);
  425. { this is needed to get correct framepointer push for local
  426. forward functions !! }
  427. pd^.parast^.symtablelevel:=lexlevel;
  428. end;
  429. if assigned (Procinfo._Class) and
  430. not(Procinfo._Class^.is_class) and
  431. (pd^.proctypeoption in [potype_constructor,potype_destructor]) then
  432. inc(paramoffset,target_os.size_of_pointer);
  433. { self pointer offset }
  434. { self isn't pushed in nested procedure of methods }
  435. if assigned(procinfo._class) and (lexlevel=normal_function_level) then
  436. begin
  437. procinfo.ESI_offset:=paramoffset;
  438. if assigned(aktprocsym^.definition) and
  439. not(po_containsself in aktprocsym^.definition^.procoptions) then
  440. inc(paramoffset,target_os.size_of_pointer);
  441. end;
  442. { destructor flag ? }
  443. if assigned (Procinfo._Class) and
  444. procinfo._class^.is_class and
  445. (pd^.proctypeoption=potype_destructor) then
  446. inc(paramoffset,target_os.size_of_pointer);
  447. procinfo.call_offset:=paramoffset;
  448. pd^.parast^.datasize:=0;
  449. pd^.nextoverloaded:=aktprocsym^.definition;
  450. aktprocsym^.definition:=pd;
  451. aktprocsym^.definition^.fileinfo:=procstartfilepos;
  452. aktprocsym^.definition^.setmangledname(hs);
  453. aktprocsym^.definition^.procsym:=aktprocsym;
  454. { update also the current filepos for aktprocsym }
  455. aktprocsym^.fileinfo:=procstartfilepos;
  456. if not parse_only then
  457. begin
  458. overloaded_level:=0;
  459. { we need another procprefix !!! }
  460. { count, but only those in the same unit !!}
  461. while assigned(pd) and
  462. (pd^.owner^.symtabletype in [globalsymtable,staticsymtable]) do
  463. begin
  464. { only count already implemented functions }
  465. if not(pd^.forwarddef) then
  466. inc(overloaded_level);
  467. pd:=pd^.nextoverloaded;
  468. end;
  469. if overloaded_level>0 then
  470. procprefix:=hs+'$'+tostr(overloaded_level)+'$'
  471. else
  472. procprefix:=hs+'$';
  473. end;
  474. { this must also be inserted in the right symtable !! PM }
  475. { otherwise we get subbtle problems with
  476. definitions of args defs in staticsymtable for
  477. implementation of a global method }
  478. if token=_LKLAMMER then
  479. formal_parameter_list;
  480. { so we only restore the symtable now }
  481. symtablestack:=st;
  482. if (options=potype_operator) then
  483. overloaded_operators[optoken]:=aktprocsym;
  484. end;
  485. procedure parse_proc_dec;
  486. var
  487. hs : string;
  488. isclassmethod : boolean;
  489. begin
  490. inc(lexlevel);
  491. { read class method }
  492. if token=_CLASS then
  493. begin
  494. consume(_CLASS);
  495. isclassmethod:=true;
  496. end
  497. else
  498. isclassmethod:=false;
  499. case token of
  500. _FUNCTION : begin
  501. consume(_FUNCTION);
  502. parse_proc_head(potype_none);
  503. if token<>_COLON then
  504. begin
  505. if not(aktprocsym^.definition^.forwarddef) or
  506. (m_repeat_forward in aktmodeswitches) then
  507. begin
  508. consume(_COLON);
  509. consume_all_until(_SEMICOLON);
  510. end;
  511. end
  512. else
  513. begin
  514. consume(_COLON);
  515. inc(testcurobject);
  516. aktprocsym^.definition^.retdef:=single_type(hs);
  517. aktprocsym^.definition^.test_if_fpu_result;
  518. dec(testcurobject);
  519. end;
  520. end;
  521. _PROCEDURE : begin
  522. consume(_PROCEDURE);
  523. parse_proc_head(potype_none);
  524. aktprocsym^.definition^.retdef:=voiddef;
  525. end;
  526. _CONSTRUCTOR : begin
  527. consume(_CONSTRUCTOR);
  528. parse_proc_head(potype_constructor);
  529. if procinfo._class^.is_class then
  530. begin
  531. { CLASS constructors return the created instance }
  532. aktprocsym^.definition^.retdef:=procinfo._class;
  533. end
  534. else
  535. begin
  536. { OBJECT constructors return a boolean }
  537. {$IfDef GDB}
  538. { GDB doesn't like unnamed types !}
  539. aktprocsym^.definition^.retdef:=globaldef('boolean');
  540. {$Else GDB}
  541. aktprocsym^.definition^.retdef:=new(porddef,init(bool8bit,0,1));
  542. {$Endif GDB}
  543. end;
  544. end;
  545. _DESTRUCTOR : begin
  546. consume(_DESTRUCTOR);
  547. parse_proc_head(potype_destructor);
  548. aktprocsym^.definition^.retdef:=voiddef;
  549. end;
  550. _OPERATOR : begin
  551. if lexlevel>normal_function_level then
  552. Message(parser_e_no_local_operator);
  553. consume(_OPERATOR);
  554. if not(token in [_PLUS..last_overloaded]) then
  555. Message(parser_e_overload_operator_failed);
  556. optoken:=token;
  557. consume(Token);
  558. procinfo.flags:=procinfo.flags or pi_operator;
  559. parse_proc_head(potype_operator);
  560. if token<>_ID then
  561. begin
  562. opsym:=nil;
  563. if not(m_result in aktmodeswitches) then
  564. consume(_ID);
  565. end
  566. else
  567. begin
  568. opsym:=new(pvarsym,init(pattern,voiddef));
  569. consume(_ID);
  570. end;
  571. if not try_to_consume(_COLON) then
  572. begin
  573. consume(_COLON);
  574. aktprocsym^.definition^.retdef:=generrordef;
  575. consume_all_until(_SEMICOLON);
  576. end
  577. else
  578. begin
  579. aktprocsym^.definition^.retdef:=
  580. single_type(hs);
  581. aktprocsym^.definition^.test_if_fpu_result;
  582. if (optoken in [_EQUAL,_GT,_LT,_GTE,_LTE]) and
  583. ((aktprocsym^.definition^.retdef^.deftype<>
  584. orddef) or (porddef(aktprocsym^.definition^.
  585. retdef)^.typ<>bool8bit)) then
  586. Message(parser_e_comparative_operator_return_boolean);
  587. if assigned(opsym) then
  588. opsym^.definition:=aktprocsym^.definition^.retdef;
  589. { We need to add the retrun type in the mangledname
  590. to allow overloading with just different results !! (PM) }
  591. aktprocsym^.definition^.setmangledname(
  592. aktprocsym^.definition^.mangledname+'$$'+hs);
  593. end;
  594. end;
  595. end;
  596. if isclassmethod and
  597. assigned(aktprocsym) then
  598. {$ifdef INCLUDEOK}
  599. include(aktprocsym^.definition^.procoptions,po_classmethod);
  600. {$else}
  601. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_classmethod];
  602. {$endif}
  603. consume(_SEMICOLON);
  604. dec(lexlevel);
  605. end;
  606. {****************************************************************************
  607. Procedure directive handlers
  608. ****************************************************************************}
  609. {$ifdef tp}
  610. {$F+}
  611. {$endif}
  612. procedure pd_far(const procnames:Tstringcontainer);
  613. begin
  614. Message(parser_w_proc_far_ignored);
  615. end;
  616. procedure pd_near(const procnames:Tstringcontainer);
  617. begin
  618. Message(parser_w_proc_near_ignored);
  619. end;
  620. procedure pd_export(const procnames:Tstringcontainer);
  621. begin
  622. if assigned(procinfo._class) then
  623. Message(parser_e_methods_dont_be_export);
  624. if lexlevel<>normal_function_level then
  625. Message(parser_e_dont_nest_export);
  626. { only os/2 needs this }
  627. if target_info.target=target_i386_os2 then
  628. begin
  629. procnames.insert(realname);
  630. procinfo.exported:=true;
  631. if cs_link_deffile in aktglobalswitches then
  632. deffile.AddExport(aktprocsym^.definition^.mangledname);
  633. end;
  634. end;
  635. procedure pd_inline(const procnames:Tstringcontainer);
  636. begin
  637. if not(cs_support_inline in aktmoduleswitches) then
  638. Message(parser_e_proc_inline_not_supported);
  639. end;
  640. procedure pd_forward(const procnames:Tstringcontainer);
  641. begin
  642. aktprocsym^.definition^.forwarddef:=true;
  643. {$ifdef INCLUDEOK}
  644. include(aktprocsym^.symoptions,sp_forwarddef);
  645. {$else}
  646. aktprocsym^.symoptions:=aktprocsym^.symoptions+[sp_forwarddef];
  647. {$endif}
  648. end;
  649. procedure pd_stdcall(const procnames:Tstringcontainer);
  650. begin
  651. end;
  652. procedure pd_safecall(const procnames:Tstringcontainer);
  653. begin
  654. end;
  655. procedure pd_alias(const procnames:Tstringcontainer);
  656. begin
  657. consume(_COLON);
  658. procnames.insert(get_stringconst);
  659. end;
  660. procedure pd_asmname(const procnames:Tstringcontainer);
  661. begin
  662. aktprocsym^.definition^.setmangledname(target_os.Cprefix+pattern);
  663. if token=_CCHAR then
  664. consume(_CCHAR)
  665. else
  666. consume(_CSTRING);
  667. { we don't need anything else }
  668. aktprocsym^.definition^.forwarddef:=false;
  669. end;
  670. procedure pd_intern(const procnames:Tstringcontainer);
  671. begin
  672. consume(_COLON);
  673. aktprocsym^.definition^.extnumber:=get_intconst;
  674. end;
  675. procedure pd_system(const procnames:Tstringcontainer);
  676. begin
  677. aktprocsym^.definition^.setmangledname(realname);
  678. end;
  679. procedure pd_abstract(const procnames:Tstringcontainer);
  680. begin
  681. if (po_virtualmethod in aktprocsym^.definition^.procoptions) then
  682. {$ifdef INCLUDEOK}
  683. include(aktprocsym^.definition^.procoptions,po_abstractmethod)
  684. {$else}
  685. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_abstractmethod]
  686. {$endif}
  687. else
  688. Message(parser_e_only_virtual_methods_abstract);
  689. { the method is defined }
  690. aktprocsym^.definition^.forwarddef:=false;
  691. end;
  692. procedure pd_virtual(const procnames:Tstringcontainer);
  693. begin
  694. if (aktprocsym^.definition^.proctypeoption=potype_constructor) and
  695. not(aktprocsym^.definition^._class^.is_class) then
  696. Message(parser_e_constructor_cannot_be_not_virtual);
  697. end;
  698. procedure pd_static(const procnames:Tstringcontainer);
  699. begin
  700. if (cs_static_keyword in aktmoduleswitches) then
  701. begin
  702. {$ifdef INCLUDEOK}
  703. include(aktprocsym^.symoptions,sp_static);
  704. include(aktprocsym^.definition^.procoptions,po_staticmethod);
  705. {$else}
  706. aktprocsym^.symoptions:=aktprocsym^.symoptions+[sp_static];
  707. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_staticmethod];
  708. {$endif}
  709. end;
  710. end;
  711. procedure pd_override(const procnames:Tstringcontainer);
  712. begin
  713. if not(aktprocsym^.definition^._class^.is_class) then
  714. Message(parser_e_no_object_override);
  715. end;
  716. procedure pd_message(const procnames:Tstringcontainer);
  717. var
  718. pt : ptree;
  719. begin
  720. { check parameter type }
  721. if not(po_containsself in aktprocsym^.definition^.procoptions) and
  722. (assigned(aktprocsym^.definition^.para1^.next) or
  723. (aktprocsym^.definition^.para1^.paratyp<>vs_var)) then
  724. Message(parser_e_ill_msg_param);
  725. pt:=comp_expr(true);
  726. do_firstpass(pt);
  727. if pt^.treetype=stringconstn then
  728. begin
  729. {$ifdef INCLUDEOK}
  730. include(aktprocsym^.definition^.procoptions,po_msgstr);
  731. {$else}
  732. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_msgstr];
  733. {$endif}
  734. aktprocsym^.definition^.messageinf.str:=strnew(pt^.value_str);
  735. end
  736. else
  737. if is_constintnode(pt) then
  738. begin
  739. {$ifdef INCLUDEOK}
  740. include(aktprocsym^.definition^.procoptions,po_msgint);
  741. {$else}
  742. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+[po_msgint];
  743. {$endif}
  744. aktprocsym^.definition^.messageinf.i:=pt^.value;
  745. end
  746. else
  747. Message(parser_e_ill_msg_expr);
  748. disposetree(pt);
  749. end;
  750. procedure pd_cdecl(const procnames:Tstringcontainer);
  751. begin
  752. if aktprocsym^.definition^.deftype<>procvardef then
  753. aktprocsym^.definition^.setmangledname(target_os.Cprefix+realname);
  754. end;
  755. procedure pd_register(const procnames:Tstringcontainer);
  756. begin
  757. Message(parser_w_proc_register_ignored);
  758. end;
  759. procedure pd_syscall(const procnames:Tstringcontainer);
  760. begin
  761. aktprocsym^.definition^.forwarddef:=false;
  762. aktprocsym^.definition^.extnumber:=get_intconst;
  763. end;
  764. procedure pd_external(const procnames:Tstringcontainer);
  765. {
  766. If import_dll=nil the procedure is assumed to be in another
  767. object file. In that object file it should have the name to
  768. which import_name is pointing to. Otherwise, the procedure is
  769. assumed to be in the DLL to which import_dll is pointing to. In
  770. that case either import_nr<>0 or import_name<>nil is true, so
  771. the procedure is either imported by number or by name. (DM)
  772. }
  773. var
  774. import_dll,
  775. import_name : string;
  776. import_nr : word;
  777. begin
  778. aktprocsym^.definition^.forwarddef:=false;
  779. { If the procedure should be imported from a DLL, a constant string follows.
  780. This isn't really correct, an contant string expression follows
  781. so we check if an semicolon follows, else a string constant have to
  782. follow (FK) }
  783. import_nr:=0;
  784. import_name:='';
  785. if not(token=_SEMICOLON) and not(idtoken=_NAME) then
  786. begin
  787. import_dll:=get_stringconst;
  788. if (idtoken=_NAME) then
  789. begin
  790. consume(_NAME);
  791. import_name:=get_stringconst;
  792. end;
  793. if (idtoken=_INDEX) then
  794. begin
  795. {After the word index follows the index number in the DLL.}
  796. consume(_INDEX);
  797. import_nr:=get_intconst;
  798. end;
  799. if (import_nr=0) and (import_name='') then
  800. {if (aktprocsym^.definition^.options and pocdecl)<>0 then
  801. import_name:=aktprocsym^.definition^.mangledname
  802. else
  803. Message(parser_w_empty_import_name);}
  804. { this should work both for win32 and Linux !! PM }
  805. import_name:=realname;
  806. if not(current_module^.uses_imports) then
  807. begin
  808. current_module^.uses_imports:=true;
  809. importlib^.preparelib(current_module^.modulename^);
  810. end;
  811. if not(m_repeat_forward in aktmodeswitches) then
  812. begin
  813. { we can only have one overloaded here ! }
  814. if assigned(aktprocsym^.definition^.nextoverloaded) then
  815. importlib^.importprocedure(aktprocsym^.definition^.nextoverloaded^.mangledname,
  816. import_dll,import_nr,import_name)
  817. else
  818. importlib^.importprocedure(aktprocsym^.mangledname,import_dll,import_nr,import_name);
  819. end
  820. else
  821. importlib^.importprocedure(aktprocsym^.mangledname,import_dll,import_nr,import_name);
  822. end
  823. else
  824. begin
  825. if (idtoken=_NAME) then
  826. begin
  827. consume(_NAME);
  828. import_name:=get_stringconst;
  829. aktprocsym^.definition^.setmangledname(import_name);
  830. end
  831. else
  832. begin
  833. { external shouldn't override the cdecl/system name }
  834. if not (pocall_clearstack in aktprocsym^.definition^.proccalloptions) then
  835. aktprocsym^.definition^.setmangledname(aktprocsym^.name);
  836. end;
  837. end;
  838. end;
  839. {$ifdef TP}
  840. {$F-}
  841. {$endif}
  842. function parse_proc_direc(const proc_names:Tstringcontainer;var pdflags:word):boolean;
  843. {
  844. Parse the procedure directive, returns true if a correct directive is found
  845. }
  846. const
  847. namelength=15;
  848. type
  849. pd_handler=procedure(const procnames:Tstringcontainer);
  850. proc_dir_rec=record
  851. idtok : ttoken;
  852. pd_flags : longint;
  853. handler : pd_handler;
  854. pocall : tproccalloptions;
  855. pooption : tprocoptions;
  856. mutexclpocall : tproccalloptions;
  857. mutexclpotype : tproctypeoptions;
  858. mutexclpo : tprocoptions;
  859. end;
  860. const
  861. {Should contain the number of procedure directives we support.}
  862. num_proc_directives=29;
  863. proc_direcdata:array[1..num_proc_directives] of proc_dir_rec=
  864. (
  865. (
  866. idtok:_ABSTRACT;
  867. pd_flags : pd_interface+pd_object;
  868. handler : {$ifndef TP}@{$endif}pd_abstract;
  869. pocall : [];
  870. pooption : [po_abstractmethod];
  871. mutexclpocall : [pocall_internproc,pocall_inline];
  872. mutexclpotype : [potype_constructor,potype_destructor];
  873. mutexclpo : [po_exports,po_interrupt,po_external]
  874. ),(
  875. idtok:_ALIAS;
  876. pd_flags : pd_implemen+pd_body;
  877. handler : {$ifndef TP}@{$endif}pd_alias;
  878. pocall : [];
  879. pooption : [];
  880. mutexclpocall : [pocall_inline];
  881. mutexclpotype : [];
  882. mutexclpo : [po_external]
  883. ),(
  884. idtok:_ASMNAME;
  885. pd_flags : pd_interface+pd_implemen;
  886. handler : {$ifndef TP}@{$endif}pd_asmname;
  887. pocall : [pocall_cdecl,pocall_clearstack];
  888. pooption : [po_external];
  889. mutexclpocall : [pocall_internproc];
  890. mutexclpotype : [];
  891. mutexclpo : [po_external]
  892. ),(
  893. idtok:_ASSEMBLER;
  894. pd_flags : pd_implemen+pd_body;
  895. handler : nil;
  896. pocall : [];
  897. pooption : [po_assembler];
  898. mutexclpocall : [];
  899. mutexclpotype : [];
  900. mutexclpo : [po_external]
  901. ),(
  902. idtok:_CDECL;
  903. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  904. handler : {$ifndef TP}@{$endif}pd_cdecl;
  905. pocall : [pocall_cdecl,pocall_clearstack];
  906. pooption : [po_savestdregs];
  907. mutexclpocall : [pocall_internproc,pocall_leftright,pocall_inline];
  908. mutexclpotype : [];
  909. mutexclpo : [po_assembler,po_external]
  910. ),(
  911. idtok:_DYNAMIC;
  912. pd_flags : pd_interface+pd_object;
  913. handler : {$ifndef TP}@{$endif}pd_virtual;
  914. pocall : [];
  915. pooption : [po_virtualmethod];
  916. mutexclpocall : [pocall_internproc,pocall_inline];
  917. mutexclpotype : [];
  918. mutexclpo : [po_exports,po_interrupt,po_external]
  919. ),(
  920. idtok:_EXPORT;
  921. pd_flags : pd_body+pd_global+pd_interface+pd_implemen{??};
  922. handler : {$ifndef TP}@{$endif}pd_export;
  923. pocall : [];
  924. pooption : [po_exports];
  925. mutexclpocall : [pocall_internproc,pocall_inline];
  926. mutexclpotype : [];
  927. mutexclpo : [po_external,po_interrupt]
  928. ),(
  929. idtok:_EXTERNAL;
  930. pd_flags : pd_implemen+pd_interface;
  931. handler : {$ifndef TP}@{$endif}pd_external;
  932. pocall : [];
  933. pooption : [po_external];
  934. mutexclpocall : [pocall_internproc,pocall_inline,pocall_palmossyscall];
  935. mutexclpotype : [];
  936. mutexclpo : [po_exports,po_interrupt,po_assembler]
  937. ),(
  938. idtok:_FAR;
  939. pd_flags : pd_implemen+pd_body+pd_interface+pd_procvar;
  940. handler : {$ifndef TP}@{$endif}pd_far;
  941. pocall : [];
  942. pooption : [];
  943. mutexclpocall : [pocall_internproc,pocall_inline];
  944. mutexclpotype : [];
  945. mutexclpo : []
  946. ),(
  947. idtok:_FORWARD;
  948. pd_flags : pd_implemen;
  949. handler : {$ifndef TP}@{$endif}pd_forward;
  950. pocall : [];
  951. pooption : [];
  952. mutexclpocall : [pocall_internproc,pocall_inline];
  953. mutexclpotype : [];
  954. mutexclpo : [po_external]
  955. ),(
  956. idtok:_INLINE;
  957. pd_flags : pd_implemen+pd_body;
  958. handler : {$ifndef TP}@{$endif}pd_inline;
  959. pocall : [pocall_inline];
  960. pooption : [];
  961. mutexclpocall : [pocall_internproc];
  962. mutexclpotype : [potype_constructor,potype_destructor];
  963. mutexclpo : [po_exports,po_external,po_interrupt]
  964. ),(
  965. idtok:_INTERNCONST;
  966. pd_flags : pd_implemen+pd_body;
  967. handler : {$ifndef TP}@{$endif}pd_intern;
  968. pocall : [pocall_internconst];
  969. pooption : [];
  970. mutexclpocall : [pocall_internproc];
  971. mutexclpotype : [potype_operator];
  972. mutexclpo : []
  973. ),(
  974. idtok:_INTERNPROC;
  975. pd_flags : pd_implemen;
  976. handler : {$ifndef TP}@{$endif}pd_intern;
  977. pocall : [pocall_internproc];
  978. pooption : [];
  979. mutexclpocall : [pocall_internconst,pocall_inline,pocall_clearstack,pocall_leftright,pocall_cdecl];
  980. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  981. mutexclpo : [po_exports,po_external,po_interrupt,po_assembler,po_iocheck]
  982. ),(
  983. idtok:_INTERRUPT;
  984. pd_flags : pd_implemen+pd_body;
  985. handler : nil;
  986. pocall : [];
  987. pooption : [po_interrupt];
  988. mutexclpocall : [pocall_internproc,pocall_cdecl,pocall_clearstack,pocall_leftright,pocall_inline];
  989. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  990. mutexclpo : [po_external]
  991. ),(
  992. idtok:_IOCHECK;
  993. pd_flags : pd_implemen+pd_body;
  994. handler : nil;
  995. pocall : [];
  996. pooption : [po_iocheck];
  997. mutexclpocall : [pocall_internproc];
  998. mutexclpotype : [];
  999. mutexclpo : [po_external]
  1000. ),(
  1001. idtok:_MESSAGE;
  1002. pd_flags : pd_interface+pd_object;
  1003. handler : {$ifndef TP}@{$endif}pd_message;
  1004. pocall : [];
  1005. pooption : []; { can be po_msgstr or po_msgint }
  1006. mutexclpocall : [pocall_inline,pocall_internproc];
  1007. mutexclpotype : [potype_constructor,potype_destructor,potype_operator];
  1008. mutexclpo : [po_interrupt,po_external]
  1009. ),(
  1010. idtok:_NEAR;
  1011. pd_flags : pd_implemen+pd_body+pd_procvar;
  1012. handler : {$ifndef TP}@{$endif}pd_near;
  1013. pocall : [];
  1014. pooption : [];
  1015. mutexclpocall : [pocall_internproc];
  1016. mutexclpotype : [];
  1017. mutexclpo : []
  1018. ),(
  1019. idtok:_OVERRIDE;
  1020. pd_flags : pd_interface+pd_object;
  1021. handler : {$ifndef TP}@{$endif}pd_override;
  1022. pocall : [];
  1023. pooption : [po_overridingmethod,po_virtualmethod];
  1024. mutexclpocall : [pocall_inline,pocall_internproc];
  1025. mutexclpotype : [];
  1026. mutexclpo : [po_exports,po_external,po_interrupt]
  1027. ),(
  1028. idtok:_PASCAL;
  1029. pd_flags : pd_implemen+pd_body+pd_procvar;
  1030. handler : nil;
  1031. pocall : [pocall_leftright];
  1032. pooption : [];
  1033. mutexclpocall : [pocall_internproc];
  1034. mutexclpotype : [];
  1035. mutexclpo : [po_external]
  1036. ),(
  1037. idtok:_POPSTACK;
  1038. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1039. handler : nil;
  1040. pocall : [pocall_clearstack];
  1041. pooption : [];
  1042. mutexclpocall : [pocall_inline,pocall_internproc];
  1043. mutexclpotype : [];
  1044. mutexclpo : [po_assembler,po_external]
  1045. ),(
  1046. idtok:_PUBLIC;
  1047. pd_flags : pd_implemen+pd_body+pd_global+pd_notobject;
  1048. handler : nil;
  1049. pocall : [];
  1050. pooption : [];
  1051. mutexclpocall : [pocall_internproc,pocall_inline];
  1052. mutexclpotype : [];
  1053. mutexclpo : [po_external]
  1054. ),(
  1055. idtok:_REGISTER;
  1056. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1057. handler : {$ifndef TP}@{$endif}pd_register;
  1058. pocall : [pocall_register];
  1059. pooption : [];
  1060. mutexclpocall : [pocall_leftright,pocall_cdecl,pocall_internproc];
  1061. mutexclpotype : [];
  1062. mutexclpo : [po_external]
  1063. ),(
  1064. idtok:_SAFECALL;
  1065. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1066. handler : {$ifndef TP}@{$endif}pd_safecall;
  1067. pocall : [pocall_safecall];
  1068. pooption : [po_savestdregs];
  1069. mutexclpocall : [pocall_leftright,pocall_cdecl,pocall_internproc,pocall_inline];
  1070. mutexclpotype : [];
  1071. mutexclpo : [po_external]
  1072. ),(
  1073. idtok:_SAVEREGISTERS;
  1074. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1075. handler : nil;
  1076. pocall : [];
  1077. pooption : [po_saveregisters];
  1078. mutexclpocall : [pocall_internproc];
  1079. mutexclpotype : [];
  1080. mutexclpo : [po_external]
  1081. ),(
  1082. idtok:_STATIC;
  1083. pd_flags : pd_interface+pd_object;
  1084. handler : {$ifndef TP}@{$endif}pd_static;
  1085. pocall : [];
  1086. pooption : [po_staticmethod];
  1087. mutexclpocall : [pocall_inline,pocall_internproc];
  1088. mutexclpotype : [potype_constructor,potype_destructor];
  1089. mutexclpo : [po_external,po_interrupt,po_exports]
  1090. ),(
  1091. idtok:_STDCALL;
  1092. pd_flags : pd_interface+pd_implemen+pd_body+pd_procvar;
  1093. handler : {$ifndef TP}@{$endif}pd_stdcall;
  1094. pocall : [pocall_stdcall];
  1095. pooption : [po_savestdregs];
  1096. mutexclpocall : [pocall_leftright,pocall_cdecl,pocall_inline,pocall_internproc];
  1097. mutexclpotype : [];
  1098. mutexclpo : [po_external]
  1099. ),(
  1100. idtok:_SYSCALL;
  1101. pd_flags : pd_interface;
  1102. handler : {$ifndef TP}@{$endif}pd_syscall;
  1103. pocall : [pocall_palmossyscall];
  1104. pooption : [];
  1105. mutexclpocall : [pocall_cdecl,pocall_inline,pocall_internproc];
  1106. mutexclpotype : [];
  1107. mutexclpo : [po_external,po_assembler,po_interrupt,po_exports]
  1108. ),(
  1109. idtok:_SYSTEM;
  1110. pd_flags : pd_implemen;
  1111. handler : {$ifndef TP}@{$endif}pd_system;
  1112. pocall : [pocall_clearstack];
  1113. pooption : [];
  1114. mutexclpocall : [pocall_leftright,pocall_inline,pocall_internproc];
  1115. mutexclpotype : [];
  1116. mutexclpo : [po_external,po_assembler,po_interrupt]
  1117. ),(
  1118. idtok:_VIRTUAL;
  1119. pd_flags : pd_interface+pd_object;
  1120. handler : {$ifndef TP}@{$endif}pd_virtual;
  1121. pocall : [];
  1122. pooption : [po_virtualmethod];
  1123. mutexclpocall : [pocall_inline,pocall_internproc];
  1124. mutexclpotype : [];
  1125. mutexclpo : [po_external,po_interrupt,po_exports]
  1126. )
  1127. );
  1128. var
  1129. p : longint;
  1130. found : boolean;
  1131. name : string;
  1132. begin
  1133. parse_proc_direc:=false;
  1134. name:=pattern;
  1135. found:=false;
  1136. for p:=1 to num_proc_directives do
  1137. if proc_direcdata[p].idtok=idtoken then
  1138. begin
  1139. found:=true;
  1140. break;
  1141. end;
  1142. { Check if the procedure directive is known }
  1143. if not found then
  1144. begin
  1145. { parsing a procvar type the name can be any
  1146. next variable !! }
  1147. if (pdflags and (pd_procvar or pd_object))=0 then
  1148. Message1(parser_w_unknown_proc_directive_ignored,name);
  1149. exit;
  1150. end;
  1151. { static needs a special treatment }
  1152. if (idtoken=_STATIC) and not (cs_static_keyword in aktmoduleswitches) then
  1153. exit;
  1154. { Conflicts between directives ? }
  1155. if (aktprocsym^.definition^.proctypeoption in proc_direcdata[p].mutexclpotype) or
  1156. ((aktprocsym^.definition^.proccalloptions*proc_direcdata[p].mutexclpocall)<>[]) or
  1157. ((aktprocsym^.definition^.procoptions*proc_direcdata[p].mutexclpo)<>[]) then
  1158. begin
  1159. Message1(parser_e_proc_dir_conflict,name);
  1160. exit;
  1161. end;
  1162. { Check if the directive is only for objects }
  1163. if ((proc_direcdata[p].pd_flags and pd_object)<>0) and
  1164. not assigned(aktprocsym^.definition^._class) then
  1165. begin
  1166. exit;
  1167. end;
  1168. { check if method and directive not for object public }
  1169. if ((proc_direcdata[p].pd_flags and pd_notobject)<>0) and
  1170. assigned(aktprocsym^.definition^._class) then
  1171. begin
  1172. exit;
  1173. end;
  1174. { consume directive, and turn flag on }
  1175. consume(token);
  1176. parse_proc_direc:=true;
  1177. { Check the pd_flags if the directive should be allowed }
  1178. if ((pdflags and pd_interface)<>0) and
  1179. ((proc_direcdata[p].pd_flags and pd_interface)=0) then
  1180. begin
  1181. Message1(parser_e_proc_dir_not_allowed_in_interface,name);
  1182. exit;
  1183. end;
  1184. if ((pdflags and pd_implemen)<>0) and
  1185. ((proc_direcdata[p].pd_flags and pd_implemen)=0) then
  1186. begin
  1187. Message1(parser_e_proc_dir_not_allowed_in_implementation,name);
  1188. exit;
  1189. end;
  1190. if ((pdflags and pd_procvar)<>0) and
  1191. ((proc_direcdata[p].pd_flags and pd_procvar)=0) then
  1192. begin
  1193. Message1(parser_e_proc_dir_not_allowed_in_procvar,name);
  1194. exit;
  1195. end;
  1196. { Return the new pd_flags }
  1197. if (proc_direcdata[p].pd_flags and pd_body)=0 then
  1198. pdflags:=pdflags and (not pd_body);
  1199. if (proc_direcdata[p].pd_flags and pd_global)<>0 then
  1200. pdflags:=pdflags or pd_global;
  1201. { Add the correct flag }
  1202. aktprocsym^.definition^.proccalloptions:=aktprocsym^.definition^.proccalloptions+proc_direcdata[p].pocall;
  1203. aktprocsym^.definition^.procoptions:=aktprocsym^.definition^.procoptions+proc_direcdata[p].pooption;
  1204. { Adjust positions of args for cdecl or stdcall }
  1205. if (aktprocsym^.definition^.deftype=procdef) and
  1206. (([pocall_cdecl,pocall_stdcall]*aktprocsym^.definition^.proccalloptions)<>[]) then
  1207. aktprocsym^.definition^.parast^.set_alignment(target_os.size_of_longint);
  1208. { Call the handler }
  1209. if pointer({$ifndef FPC}@{$endif}proc_direcdata[p].handler)<>nil then
  1210. proc_direcdata[p].handler(proc_names);
  1211. end;
  1212. {***************************************************************************}
  1213. function check_identical : boolean;
  1214. {
  1215. Search for idendical definitions,
  1216. if there is a forward, then kill this.
  1217. Returns the result of the forward check.
  1218. Removed from unter_dec to keep the source readable
  1219. }
  1220. var
  1221. hd,pd : Pprocdef;
  1222. storeparast : psymtable;
  1223. ad,fd : psym;
  1224. s : string;
  1225. begin
  1226. check_identical:=false;
  1227. pd:=aktprocsym^.definition;
  1228. if assigned(pd) then
  1229. begin
  1230. { Is there an overload/forward ? }
  1231. if assigned(pd^.nextoverloaded) then
  1232. begin
  1233. { walk the procdef list }
  1234. while (assigned(pd)) and (assigned(pd^.nextoverloaded)) do
  1235. begin
  1236. if not(m_repeat_forward in aktmodeswitches) or
  1237. (equal_paras(aktprocsym^.definition^.para1,pd^.nextoverloaded^.para1,false) and
  1238. { for operators equal_paras is not enough !! }
  1239. ((aktprocsym^.definition^.proctypeoption<>potype_operator) or (optoken<>_ASSIGNMENT) or
  1240. is_equal(pd^.nextoverloaded^.retdef,aktprocsym^.definition^.retdef))) then
  1241. begin
  1242. if pd^.nextoverloaded^.forwarddef then
  1243. { remove the forward definition but don't delete it, }
  1244. { the symtable is the owner !! }
  1245. begin
  1246. hd:=pd^.nextoverloaded;
  1247. { Check if the procedure type and return type are correct }
  1248. if (hd^.proctypeoption<>aktprocsym^.definition^.proctypeoption) or
  1249. (not(is_equal(hd^.retdef,aktprocsym^.definition^.retdef)) and
  1250. (m_repeat_forward in aktmodeswitches)) then
  1251. begin
  1252. Message1(parser_e_header_dont_match_forward,aktprocsym^.demangledName);
  1253. exit;
  1254. end;
  1255. { Check calling convention, no check for internconst,internproc which
  1256. are only defined in interface or implementation }
  1257. if (hd^.proccalloptions-[pocall_internconst,pocall_internproc]<>
  1258. aktprocsym^.definition^.proccalloptions-[pocall_internconst,pocall_internproc]) then
  1259. begin
  1260. { only trigger an error, becuase it doesn't hurt }
  1261. Message(parser_e_call_convention_dont_match_forward);
  1262. end;
  1263. { manglednames are equal? }
  1264. hd^.count:=false;
  1265. if (m_repeat_forward in aktmodeswitches) or
  1266. aktprocsym^.definition^.haspara then
  1267. begin
  1268. if (hd^.mangledname<>aktprocsym^.definition^.mangledname) then
  1269. begin
  1270. { When overloading is not possible then we issue an error }
  1271. if not(m_repeat_forward in aktmodeswitches) then
  1272. begin
  1273. Message1(parser_e_header_dont_match_forward,aktprocsym^.demangledName);
  1274. exit;
  1275. end;
  1276. if not(po_external in aktprocsym^.definition^.procoptions) then
  1277. Message2(parser_n_interface_name_diff_implementation_name,hd^.mangledname,
  1278. aktprocsym^.definition^.mangledname);
  1279. { reset the mangledname of the interface part to be sure }
  1280. { this is wrong because the mangled name might have been used already !! }
  1281. if hd^.is_used then
  1282. renameasmsymbol(hd^.mangledname,aktprocsym^.definition^.mangledname);
  1283. hd^.setmangledname(aktprocsym^.definition^.mangledname);
  1284. { so we need to keep the name of interface !!
  1285. No!!!! The procedure directives can change the mangledname.
  1286. I fixed this by first calling check_identical and then doing
  1287. the proc directives, but this is not a good solution.(DM)}
  1288. { this is also wrong (PM)
  1289. aktprocsym^.definition^.setmangledname(hd^.mangledname);}
  1290. end
  1291. else
  1292. begin
  1293. { If mangled names are equal, therefore }
  1294. { they have the same number of parameters }
  1295. { Therefore we can check the name of these }
  1296. { parameters... }
  1297. if hd^.forwarddef and aktprocsym^.definition^.forwarddef then
  1298. begin
  1299. Message1(parser_e_function_already_declared_public_forward,aktprocsym^.demangledName);
  1300. Check_identical:=true;
  1301. { Remove other forward from the list to reduce errors }
  1302. pd^.nextoverloaded:=pd^.nextoverloaded^.nextoverloaded;
  1303. exit;
  1304. end;
  1305. ad:=psym(hd^.parast^.symindex^.first);
  1306. fd:=psym(aktprocsym^.definition^.parast^.symindex^.first);
  1307. if assigned(ad) and assigned(fd) then
  1308. begin
  1309. while assigned(ad) and assigned(fd) do
  1310. begin
  1311. s:=ad^.name;
  1312. if s<>fd^.name then
  1313. begin
  1314. Message3(parser_e_header_different_var_names,
  1315. aktprocsym^.name,s,fd^.name);
  1316. break;
  1317. end;
  1318. { it is impossible to have a nil pointer }
  1319. { for only one parameter - since they }
  1320. { have the same number of parameters. }
  1321. { Left = next parameter. }
  1322. ad:=psym(ad^.left);
  1323. fd:=psym(fd^.left);
  1324. end;
  1325. end;
  1326. end;
  1327. end;
  1328. { also the call_offset }
  1329. hd^.parast^.address_fixup:=aktprocsym^.definition^.parast^.address_fixup;
  1330. hd^.count:=true;
  1331. { remove pd^.nextoverloaded from the list }
  1332. { and add aktprocsym^.definition }
  1333. pd^.nextoverloaded:=pd^.nextoverloaded^.nextoverloaded;
  1334. hd^.nextoverloaded:=aktprocsym^.definition^.nextoverloaded;
  1335. { Alert! All fields of aktprocsym^.definition that are modified
  1336. by the procdir handlers must be copied here!.}
  1337. hd^.forwarddef:=false;
  1338. hd^.proccalloptions:=hd^.proccalloptions + aktprocsym^.definition^.proccalloptions;
  1339. hd^.procoptions:=hd^.procoptions + aktprocsym^.definition^.procoptions;
  1340. if aktprocsym^.definition^.extnumber=-1 then
  1341. aktprocsym^.definition^.extnumber:=hd^.extnumber
  1342. else
  1343. if hd^.extnumber=-1 then
  1344. hd^.extnumber:=aktprocsym^.definition^.extnumber;
  1345. { switch parast for warning in implementation PM }
  1346. if (m_repeat_forward in aktmodeswitches) or
  1347. aktprocsym^.definition^.haspara then
  1348. begin
  1349. storeparast:=hd^.parast;
  1350. hd^.parast:=aktprocsym^.definition^.parast;
  1351. aktprocsym^.definition^.parast:=storeparast;
  1352. end;
  1353. aktprocsym^.definition:=hd;
  1354. check_identical:=true;
  1355. end
  1356. else
  1357. { abstract methods aren't forward defined, but this }
  1358. { needs another error message }
  1359. if not(po_abstractmethod in pd^.nextoverloaded^.procoptions) then
  1360. Message(parser_e_overloaded_have_same_parameters)
  1361. else
  1362. Message(parser_e_abstract_no_definition);
  1363. break;
  1364. end;
  1365. pd:=pd^.nextoverloaded;
  1366. end;
  1367. end
  1368. else
  1369. begin
  1370. { there is no overloaded, so its always identical with itself }
  1371. check_identical:=true;
  1372. end;
  1373. end;
  1374. { insert opsym only in the right symtable }
  1375. if ((procinfo.flags and pi_operator)<>0) and assigned(opsym)
  1376. and not parse_only then
  1377. begin
  1378. if ret_in_param(aktprocsym^.definition^.retdef) then
  1379. begin
  1380. pprocdef(aktprocsym^.definition)^.parast^.insert(opsym);
  1381. { this increases the data size }
  1382. { correct this to get the right ret $value }
  1383. dec(pprocdef(aktprocsym^.definition)^.parast^.datasize,opsym^.getpushsize);
  1384. { this allows to read the funcretoffset }
  1385. opsym^.address:=-4;
  1386. opsym^.varspez:=vs_var;
  1387. end
  1388. else
  1389. pprocdef(aktprocsym^.definition)^.localst^.insert(opsym);
  1390. end;
  1391. end;
  1392. procedure compile_proc_body(const proc_names:Tstringcontainer;
  1393. make_global,parent_has_class:boolean);
  1394. {
  1395. Compile the body of a procedure
  1396. }
  1397. var
  1398. oldexitlabel,oldexit2label : pasmlabel;
  1399. oldfaillabel,oldquickexitlabel:Pasmlabel;
  1400. _class,hp:Pobjectdef;
  1401. { switches can change inside the procedure }
  1402. entryswitches, exitswitches : tlocalswitches;
  1403. { code for the subroutine as tree }
  1404. {$ifdef newcg}
  1405. code:pnode;
  1406. {$else newcg}
  1407. code:ptree;
  1408. {$endif newcg}
  1409. { size of the local strackframe }
  1410. stackframe:longint;
  1411. { true when no stackframe is required }
  1412. nostackframe:boolean;
  1413. { number of bytes which have to be cleared by RET }
  1414. parasize:longint;
  1415. { filepositions }
  1416. entrypos,
  1417. savepos,
  1418. exitpos : tfileposinfo;
  1419. begin
  1420. { calculate the lexical level }
  1421. inc(lexlevel);
  1422. if lexlevel>32 then
  1423. Message(parser_e_too_much_lexlevel);
  1424. { static is also important for local procedures !! }
  1425. if (po_staticmethod in aktprocsym^.definition^.procoptions) then
  1426. allow_only_static:=true
  1427. else if (lexlevel=normal_function_level) then
  1428. allow_only_static:=false;
  1429. { save old labels }
  1430. oldexitlabel:=aktexitlabel;
  1431. oldexit2label:=aktexit2label;
  1432. oldquickexitlabel:=quickexitlabel;
  1433. oldfaillabel:=faillabel;
  1434. { get new labels }
  1435. getlabel(aktexitlabel);
  1436. getlabel(aktexit2label);
  1437. { exit for fail in constructors }
  1438. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1439. begin
  1440. getlabel(faillabel);
  1441. getlabel(quickexitlabel);
  1442. end;
  1443. { reset break and continue labels }
  1444. in_except_block:=false;
  1445. aktbreaklabel:=nil;
  1446. aktcontinuelabel:=nil;
  1447. { insert symtables for the class, by only if it is no nested function }
  1448. if assigned(procinfo._class) and not(parent_has_class) then
  1449. begin
  1450. { insert them in the reverse order ! }
  1451. hp:=nil;
  1452. repeat
  1453. _class:=procinfo._class;
  1454. while _class^.childof<>hp do
  1455. _class:=_class^.childof;
  1456. hp:=_class;
  1457. _class^.symtable^.next:=symtablestack;
  1458. symtablestack:=_class^.symtable;
  1459. until hp=procinfo._class;
  1460. end;
  1461. { insert parasymtable in symtablestack}
  1462. { only if lexlevel > 1 !!! global symtable should be right after staticsymtazble
  1463. for checking of same names used in interface and implementation !! }
  1464. if lexlevel>=normal_function_level then
  1465. begin
  1466. aktprocsym^.definition^.parast^.next:=symtablestack;
  1467. symtablestack:=aktprocsym^.definition^.parast;
  1468. symtablestack^.symtablelevel:=lexlevel;
  1469. end;
  1470. { insert localsymtable in symtablestack}
  1471. aktprocsym^.definition^.localst^.next:=symtablestack;
  1472. symtablestack:=aktprocsym^.definition^.localst;
  1473. symtablestack^.symtablelevel:=lexlevel;
  1474. { constant symbols are inserted in this symboltable }
  1475. constsymtable:=symtablestack;
  1476. { reset the temporary memory }
  1477. cleartempgen;
  1478. {$ifdef newcg}
  1479. tg.usedinproc:=[];
  1480. {$else newcg}
  1481. { no registers are used }
  1482. usedinproc:=0;
  1483. {$endif newcg}
  1484. { save entry info }
  1485. entrypos:=aktfilepos;
  1486. entryswitches:=aktlocalswitches;
  1487. {$ifdef newcg}
  1488. { parse the code ... }
  1489. if (po_assembler in aktprocsym^.definition^.procoptions) then
  1490. code:=convtree2node(assembler_block)
  1491. else
  1492. code:=convtree2node(block(current_module^.islibrary));
  1493. {$else newcg}
  1494. { parse the code ... }
  1495. if (po_assembler in aktprocsym^.definition^.procoptions) then
  1496. code:=assembler_block
  1497. else
  1498. code:=block(current_module^.islibrary);
  1499. {$endif newcg}
  1500. { get a better entry point }
  1501. if assigned(code) then
  1502. entrypos:=code^.fileinfo;
  1503. { save exit info }
  1504. exitswitches:=aktlocalswitches;
  1505. exitpos:=last_endtoken_filepos;
  1506. { save current filepos }
  1507. savepos:=aktfilepos;
  1508. {When we are called to compile the body of a unit, aktprocsym should
  1509. point to the unit initialization. If the unit has no initialization,
  1510. aktprocsym=nil. But in that case code=nil. hus we should check for
  1511. code=nil, when we use aktprocsym.}
  1512. { set the framepointer to esp for assembler functions }
  1513. { but only if the are no local variables }
  1514. { already done in assembler_block }
  1515. {$ifdef newcg}
  1516. tg.setfirsttemp(procinfo.firsttemp);
  1517. {$else newcg}
  1518. setfirsttemp(procinfo.firsttemp);
  1519. {$endif newcg}
  1520. { ... and generate assembler }
  1521. { but set the right switches for entry !! }
  1522. aktlocalswitches:=entryswitches;
  1523. {$ifndef NOPASS2}
  1524. {$ifdef newcg}
  1525. tg.setfirsttemp(procinfo.firsttemp);
  1526. {$else newcg}
  1527. if assigned(code) then
  1528. generatecode(code);
  1529. {$endif newcg}
  1530. { set switches to status at end of procedure }
  1531. aktlocalswitches:=exitswitches;
  1532. if assigned(code) then
  1533. begin
  1534. aktprocsym^.definition^.code:=code;
  1535. { the procedure is now defined }
  1536. aktprocsym^.definition^.forwarddef:=false;
  1537. {$ifdef newcg}
  1538. aktprocsym^.definition^.usedregisters:=tg.usedinproc;
  1539. {$else newcg}
  1540. aktprocsym^.definition^.usedregisters:=usedinproc;
  1541. {$endif newcg}
  1542. end;
  1543. {$ifdef newcg}
  1544. stackframe:=tg.gettempsize;
  1545. {$else newcg}
  1546. stackframe:=gettempsize;
  1547. {$endif newcg}
  1548. { first generate entry code with the correct position and switches }
  1549. aktfilepos:=entrypos;
  1550. aktlocalswitches:=entryswitches;
  1551. {$ifdef newcg}
  1552. if assigned(code) then
  1553. cg^.g_entrycode(procinfo.aktentrycode,proc_names,make_global,stackframe,parasize,nostackframe,false);
  1554. {$else newcg}
  1555. if assigned(code) then
  1556. genentrycode(procinfo.aktentrycode,proc_names,make_global,stackframe,parasize,nostackframe,false);
  1557. {$endif newcg}
  1558. { now generate exit code with the correct position and switches }
  1559. aktfilepos:=exitpos;
  1560. aktlocalswitches:=exitswitches;
  1561. if assigned(code) then
  1562. begin
  1563. {$ifdef newcg}
  1564. cg^.g_exitcode(procinfo.aktexitcode,parasize,nostackframe,false);
  1565. {$else newcg}
  1566. genexitcode(procinfo.aktexitcode,parasize,nostackframe,false);
  1567. {$endif newcg}
  1568. procinfo.aktproccode^.insertlist(procinfo.aktentrycode);
  1569. procinfo.aktproccode^.concatlist(procinfo.aktexitcode);
  1570. {$ifdef i386}
  1571. {$ifndef NoOpt}
  1572. if (cs_optimize in aktglobalswitches) and
  1573. { do not optimize pure assembler procedures }
  1574. ((procinfo.flags and pi_is_assembler)=0) then
  1575. Optimize(procinfo.aktproccode);
  1576. {$endif NoOpt}
  1577. {$endif}
  1578. { save local data (casetable) also in the same file }
  1579. if assigned(procinfo.aktlocaldata) and
  1580. (not procinfo.aktlocaldata^.empty) then
  1581. begin
  1582. procinfo.aktproccode^.concat(new(pai_section,init(sec_data)));
  1583. procinfo.aktproccode^.concatlist(procinfo.aktlocaldata);
  1584. end;
  1585. { now we can insert a cut }
  1586. if (cs_smartlink in aktmoduleswitches) then
  1587. codesegment^.concat(new(pai_cut,init));
  1588. { add the procedure to the codesegment }
  1589. codesegment^.concatlist(procinfo.aktproccode);
  1590. end;
  1591. {$else}
  1592. if assigned(code) then
  1593. firstpass(code);
  1594. {$endif NOPASS2}
  1595. { ... remove symbol tables, for the browser leave the static table }
  1596. { if (cs_browser in aktmoduleswitches) and (symtablestack^.symtabletype=staticsymtable) then
  1597. symtablestack^.next:=symtablestack^.next^.next
  1598. else }
  1599. if lexlevel>=normal_function_level then
  1600. symtablestack:=symtablestack^.next^.next
  1601. else
  1602. symtablestack:=symtablestack^.next;
  1603. { ... check for unused symbols }
  1604. { but only if there is no asm block }
  1605. if assigned(code) then
  1606. begin
  1607. if (Errorcount=0) then
  1608. begin
  1609. aktprocsym^.definition^.localst^.check_forwards;
  1610. aktprocsym^.definition^.localst^.checklabels;
  1611. end;
  1612. if (procinfo.flags and pi_uses_asm)=0 then
  1613. begin
  1614. { not for unit init, becuase the var can be used in finalize,
  1615. it will be done in proc_unit }
  1616. if not(aktprocsym^.definition^.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  1617. aktprocsym^.definition^.localst^.allsymbolsused;
  1618. aktprocsym^.definition^.parast^.allsymbolsused;
  1619. end;
  1620. end;
  1621. { the local symtables can be deleted, but the parast }
  1622. { doesn't, (checking definitons when calling a }
  1623. { function }
  1624. { not for a inline procedure !! (PM) }
  1625. { at lexlevel = 1 localst is the staticsymtable itself }
  1626. { so no dispose here !! }
  1627. if assigned(code) and
  1628. not(cs_browser in aktmoduleswitches) and
  1629. not(pocall_inline in aktprocsym^.definition^.proccalloptions) then
  1630. begin
  1631. if lexlevel>=normal_function_level then
  1632. dispose(aktprocsym^.definition^.localst,done);
  1633. aktprocsym^.definition^.localst:=nil;
  1634. end;
  1635. { only now we can remove the temps }
  1636. resettempgen;
  1637. { remove code tree, if not inline procedure }
  1638. if assigned(code) and not(pocall_inline in aktprocsym^.definition^.proccalloptions) then
  1639. {$ifdef newcg}
  1640. dispose(code,done);
  1641. {$else newcg}
  1642. disposetree(code);
  1643. {$endif newcg}
  1644. { remove class member symbol tables }
  1645. while symtablestack^.symtabletype=objectsymtable do
  1646. symtablestack:=symtablestack^.next;
  1647. { restore filepos, the switches are already set }
  1648. aktfilepos:=savepos;
  1649. { free labels }
  1650. freelabel(aktexitlabel);
  1651. freelabel(aktexit2label);
  1652. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1653. begin
  1654. freelabel(faillabel);
  1655. freelabel(quickexitlabel);
  1656. end;
  1657. { restore labels }
  1658. aktexitlabel:=oldexitlabel;
  1659. aktexit2label:=oldexit2label;
  1660. quickexitlabel:=oldquickexitlabel;
  1661. faillabel:=oldfaillabel;
  1662. { reset to normal non static function }
  1663. if (lexlevel=normal_function_level) then
  1664. allow_only_static:=false;
  1665. { previous lexlevel }
  1666. dec(lexlevel);
  1667. end;
  1668. procedure parse_proc_directives(Anames:Pstringcontainer;var pdflags:word);
  1669. {
  1670. Parse the procedure directives. It does not matter if procedure directives
  1671. are written using ;procdir; or ['procdir'] syntax.
  1672. }
  1673. var
  1674. res : boolean;
  1675. begin
  1676. while token in [_ID,_LECKKLAMMER] do
  1677. begin
  1678. if try_to_consume(_LECKKLAMMER) then
  1679. begin
  1680. repeat
  1681. parse_proc_direc(Anames^,pdflags);
  1682. until not try_to_consume(_COMMA);
  1683. consume(_RECKKLAMMER);
  1684. { we always expect at least '[];' }
  1685. res:=true;
  1686. end
  1687. else
  1688. res:=parse_proc_direc(Anames^,pdflags);
  1689. { A procedure directive is always followed by a semicolon }
  1690. if res then
  1691. consume(_SEMICOLON)
  1692. else
  1693. break;
  1694. end;
  1695. end;
  1696. procedure parse_var_proc_directives(var sym : ptypesym);
  1697. var
  1698. anames : pstringcontainer;
  1699. pdflags : word;
  1700. oldsym : pprocsym;
  1701. begin
  1702. oldsym:=aktprocsym;
  1703. anames:=new(pstringcontainer,init);
  1704. pdflags:=pd_procvar;
  1705. { we create a temporary aktprocsym to read the directives }
  1706. aktprocsym:=new(pprocsym,init(sym^.name));
  1707. { aktprocsym^.definition:=pprocdef(sym^.definition);
  1708. this breaks the rule for TESTOBJEXT !! }
  1709. pabstractprocdef(aktprocsym^.definition):=pabstractprocdef(sym^.definition);
  1710. { names should never be used anyway }
  1711. inc(lexlevel);
  1712. parse_proc_directives(anames,pdflags);
  1713. dec(lexlevel);
  1714. aktprocsym^.definition:=nil;
  1715. dispose(aktprocsym,done);
  1716. dispose(anames,done);
  1717. aktprocsym:=oldsym;
  1718. end;
  1719. procedure parse_object_proc_directives(var sym : pprocsym);
  1720. var
  1721. anames : pstringcontainer;
  1722. pdflags : word;
  1723. begin
  1724. pdflags:=pd_object;
  1725. anames:=new(pstringcontainer,init);
  1726. inc(lexlevel);
  1727. parse_proc_directives(anames,pdflags);
  1728. dec(lexlevel);
  1729. dispose(anames,done);
  1730. if (po_containsself in aktprocsym^.definition^.procoptions) and
  1731. (([po_msgstr,po_msgint]*aktprocsym^.definition^.procoptions)=[]) then
  1732. Message(parser_e_self_in_non_message_handler);
  1733. end;
  1734. procedure checkvaluepara(p:pnamedindexobject);{$ifndef FPC}far;{$endif}
  1735. var
  1736. vs : pvarsym;
  1737. s : string;
  1738. begin
  1739. with pvarsym(p)^ do
  1740. begin
  1741. if copy(name,1,3)='val' then
  1742. begin
  1743. s:=Copy(name,4,255);
  1744. if not(po_assembler in aktprocsym^.definition^.procoptions) then
  1745. begin
  1746. vs:=new(Pvarsym,init(s,definition));
  1747. vs^.fileinfo:=fileinfo;
  1748. vs^.varspez:=varspez;
  1749. aktprocsym^.definition^.localst^.insert(vs);
  1750. vs^.islocalcopy:=true;
  1751. vs^.varstate:=vs_used;
  1752. localvarsym:=vs;
  1753. end
  1754. else
  1755. begin
  1756. aktprocsym^.definition^.parast^.rename(name,s);
  1757. end;
  1758. end;
  1759. end;
  1760. end;
  1761. procedure read_proc;
  1762. {
  1763. Parses the procedure directives, then parses the procedure body, then
  1764. generates the code for it
  1765. }
  1766. var
  1767. oldprefix : string;
  1768. oldprocsym : Pprocsym;
  1769. oldprocinfo : tprocinfo;
  1770. oldconstsymtable : Psymtable;
  1771. oldfilepos : tfileposinfo;
  1772. names : Pstringcontainer;
  1773. pdflags : word;
  1774. begin
  1775. { save old state }
  1776. oldprocsym:=aktprocsym;
  1777. oldprefix:=procprefix;
  1778. oldconstsymtable:=constsymtable;
  1779. oldprocinfo:=procinfo;
  1780. { create a new procedure }
  1781. new(names,init);
  1782. codegen_newprocedure;
  1783. with procinfo do
  1784. begin
  1785. parent:=@oldprocinfo;
  1786. { clear flags }
  1787. flags:=0;
  1788. { standard frame pointer }
  1789. framepointer:=frame_pointer;
  1790. funcret_is_valid:=false;
  1791. { is this a nested function of a method ? }
  1792. _class:=oldprocinfo._class;
  1793. end;
  1794. parse_proc_dec;
  1795. { set the default function options }
  1796. if parse_only then
  1797. begin
  1798. {$ifdef INCLUDEOK}
  1799. include(aktprocsym^.symoptions,sp_forwarddef);
  1800. {$else}
  1801. aktprocsym^.symoptions:=aktprocsym^.symoptions+[sp_forwarddef];
  1802. {$endif}
  1803. aktprocsym^.definition^.forwarddef:=true;
  1804. { set also the interface flag, for better error message when the
  1805. implementation doesn't much this header }
  1806. aktprocsym^.definition^.interfacedef:=true;
  1807. pdflags:=pd_interface;
  1808. end
  1809. else
  1810. begin
  1811. pdflags:=pd_body;
  1812. if current_module^.in_implementation then
  1813. pdflags:=pdflags or pd_implemen;
  1814. if (not current_module^.is_unit) or (cs_smartlink in aktmoduleswitches) then
  1815. pdflags:=pdflags or pd_global;
  1816. procinfo.exported:=false;
  1817. aktprocsym^.definition^.forwarddef:=false;
  1818. end;
  1819. { parse the directives that may follow }
  1820. inc(lexlevel);
  1821. parse_proc_directives(names,pdflags);
  1822. dec(lexlevel);
  1823. { set aktfilepos to the beginning of the function declaration }
  1824. oldfilepos:=aktfilepos;
  1825. aktfilepos:=aktprocsym^.definition^.fileinfo;
  1826. { search for forward declarations }
  1827. if not check_identical then
  1828. begin
  1829. { A method must be forward defined (in the object declaration) }
  1830. if assigned(procinfo._class) and (not assigned(oldprocinfo._class)) then
  1831. Message(parser_e_header_dont_match_any_member);
  1832. { Give a better error if there is a forward def in the interface and only
  1833. a single implementation }
  1834. if (not aktprocsym^.definition^.forwarddef) and
  1835. assigned(aktprocsym^.definition^.nextoverloaded) and
  1836. aktprocsym^.definition^.nextoverloaded^.forwarddef and
  1837. aktprocsym^.definition^.nextoverloaded^.interfacedef and
  1838. not(assigned(aktprocsym^.definition^.nextoverloaded^.nextoverloaded)) then
  1839. Message1(parser_e_header_dont_match_forward,aktprocsym^.demangledName)
  1840. else
  1841. begin
  1842. { check the global flag }
  1843. if (procinfo.flags and pi_is_global)<>0 then
  1844. Message(parser_e_overloaded_must_be_all_global);
  1845. end
  1846. end;
  1847. { set return type here, becuase the aktprocsym^.definition can be
  1848. changed by check_identical (PFV) }
  1849. procinfo.retdef:=aktprocsym^.definition^.retdef;
  1850. { pointer to the return value ? }
  1851. if ret_in_param(procinfo.retdef) then
  1852. begin
  1853. procinfo.retoffset:=procinfo.call_offset;
  1854. inc(procinfo.call_offset,target_os.size_of_pointer);
  1855. end;
  1856. { allows to access the parameters of main functions in nested functions }
  1857. aktprocsym^.definition^.parast^.address_fixup:=procinfo.call_offset;
  1858. { when it is a value para and it needs a local copy then rename
  1859. the parameter and insert a copy in the localst. This is not done
  1860. for assembler procedures }
  1861. if (not parse_only) and (not aktprocsym^.definition^.forwarddef) then
  1862. aktprocsym^.definition^.parast^.foreach({$ifndef TP}@{$endif}checkvaluepara);
  1863. { restore file pos }
  1864. aktfilepos:=oldfilepos;
  1865. { compile procedure when a body is needed }
  1866. if (pdflags and pd_body)<>0 then
  1867. begin
  1868. Message1(parser_p_procedure_start,aktprocsym^.demangledname);
  1869. names^.insert(aktprocsym^.definition^.mangledname);
  1870. { set _FAIL as keyword if constructor }
  1871. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1872. tokeninfo[_FAIL].keyword:=m_all;
  1873. if assigned(aktprocsym^.definition^._class) then
  1874. tokeninfo[_SELF].keyword:=m_all;
  1875. compile_proc_body(names^,((pdflags and pd_global)<>0),assigned(oldprocinfo._class));
  1876. { reset _FAIL as normal }
  1877. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1878. tokeninfo[_FAIL].keyword:=m_none;
  1879. if assigned(aktprocsym^.definition^._class) and (lexlevel=main_program_level) then
  1880. tokeninfo[_SELF].keyword:=m_none;
  1881. consume(_SEMICOLON);
  1882. end;
  1883. { close }
  1884. dispose(names,done);
  1885. codegen_doneprocedure;
  1886. { Restore old state }
  1887. constsymtable:=oldconstsymtable;
  1888. { from now on all refernece to mangledname means
  1889. that the function is already used }
  1890. aktprocsym^.definition^.count:=true;
  1891. aktprocsym:=oldprocsym;
  1892. procprefix:=oldprefix;
  1893. procinfo:=oldprocinfo;
  1894. opsym:=nil;
  1895. end;
  1896. end.
  1897. {
  1898. $Log$
  1899. Revision 1.15 1999-08-19 13:02:11 pierre
  1900. + label faillabel added for _FAIL support
  1901. Revision 1.14 1999/08/10 16:24:44 pierre
  1902. * linking to C code with cdecl;external; was broken
  1903. Revision 1.13 1999/08/10 12:37:44 pierre
  1904. + procsym field of tprocdef set
  1905. Revision 1.12 1999/08/05 16:53:06 peter
  1906. * V_Fatal=1, all other V_ are also increased
  1907. * Check for local procedure when assigning procvar
  1908. * fixed comment parsing because directives
  1909. * oldtp mode directives better supported
  1910. * added some messages to errore.msg
  1911. Revision 1.11 1999/08/04 13:03:01 jonas
  1912. * all tokens now start with an underscore
  1913. * PowerPC compiles!!
  1914. Revision 1.10 1999/08/04 00:23:20 florian
  1915. * renamed i386asm and i386base to cpuasm and cpubase
  1916. Revision 1.9 1999/08/03 22:03:05 peter
  1917. * moved bitmask constants to sets
  1918. * some other type/const renamings
  1919. Revision 1.8 1999/08/03 17:09:42 florian
  1920. * the alpha compiler can be compiled now
  1921. Revision 1.7 1999/08/02 21:29:01 florian
  1922. * the main branch psub.pas is now used for
  1923. newcg compiler
  1924. Revision 1.6 1999/07/27 23:42:16 peter
  1925. * indirect type referencing is now allowed
  1926. Revision 1.5 1999/07/26 09:42:15 florian
  1927. * bugs 494-496 fixed
  1928. Revision 1.4 1999/07/11 20:10:24 peter
  1929. * merged
  1930. Revision 1.3 1999/07/02 13:02:24 peter
  1931. * merged
  1932. Revision 1.2 1999/06/17 13:19:56 pierre
  1933. * merged from 0_99_12 branch
  1934. Revision 1.1.2.4 1999/07/11 20:07:39 peter
  1935. * message crash fixed
  1936. * no error if self is used with non-string message
  1937. Revision 1.1.2.3 1999/07/11 20:04:05 pierre
  1938. * fix for problem with external without parameters in Delphi mode
  1939. Revision 1.1.2.2 1999/07/02 12:59:52 peter
  1940. * fixed parsing of message directive
  1941. Revision 1.1.2.1 1999/06/17 12:44:47 pierre
  1942. * solve problems related to assignment overloading
  1943. * support Delphi syntax for operator
  1944. * avoid problems if local procedure in operator
  1945. Revision 1.1 1999/06/11 13:21:37 peter
  1946. * reinserted
  1947. Revision 1.153 1999/06/02 22:44:14 pierre
  1948. * previous wrong log corrected
  1949. Revision 1.152 1999/06/02 22:25:46 pierre
  1950. * changed $ifdef FPC @ into $ifndef TP
  1951. Revision 1.151 1999/06/01 22:47:06 pierre
  1952. * problem with static keyword solved
  1953. Revision 1.150 1999/06/01 14:45:53 peter
  1954. * @procvar is now always needed for FPC
  1955. Revision 1.149 1999/05/31 16:42:31 peter
  1956. * interfacedef flag for procdef if it's defined in the interface, to
  1957. make a difference with 'forward;' directive forwarddef. Fixes 253
  1958. Revision 1.148 1999/05/27 19:44:52 peter
  1959. * removed oldasm
  1960. * plabel -> pasmlabel
  1961. * -a switches to source writing automaticly
  1962. * assembler readers OOPed
  1963. * asmsymbol automaticly external
  1964. * jumptables and other label fixes for asm readers
  1965. Revision 1.147 1999/05/24 08:55:27 florian
  1966. * non working safecall directiv implemented, I don't know if we
  1967. need it
  1968. Revision 1.146 1999/05/23 18:42:11 florian
  1969. * better error recovering in typed constants
  1970. * some problems with arrays of const fixed, some problems
  1971. due my previous
  1972. - the location type of array constructor is now LOC_MEM
  1973. - the pushing of high fixed
  1974. - parameter copying fixed
  1975. - zero temp. allocation removed
  1976. * small problem in the assembler writers fixed:
  1977. ref to nil wasn't written correctly
  1978. Revision 1.145 1999/05/21 13:55:09 peter
  1979. * NEWLAB for label as symbol
  1980. Revision 1.144 1999/05/18 14:15:55 peter
  1981. * containsself fixes
  1982. * checktypes()
  1983. Revision 1.143 1999/05/17 21:57:13 florian
  1984. * new temporary ansistring handling
  1985. Revision 1.142 1999/05/17 15:06:38 pierre
  1986. * fixes for object type check
  1987. Revision 1.141 1999/05/13 21:59:39 peter
  1988. * removed oldppu code
  1989. * warning if objpas is loaded from uses
  1990. * first things for new deref writing
  1991. Revision 1.140 1999/05/12 22:36:12 florian
  1992. * override isn't allowed in objects!
  1993. Revision 1.139 1999/05/10 09:01:41 peter
  1994. * small message fixes
  1995. Revision 1.138 1999/05/09 12:46:24 peter
  1996. + hint where a duplicate sym is already defined
  1997. Revision 1.137 1999/05/08 19:48:45 peter
  1998. * better error message if declaration doesn't match forward
  1999. Revision 1.136 1999/05/08 15:26:15 peter
  2000. * print also manglednames when changed
  2001. Revision 1.135 1999/05/06 10:12:10 peter
  2002. * fixed operator result offset which destroyed parast^.datasize
  2003. Revision 1.134 1999/05/01 13:24:36 peter
  2004. * merged nasm compiler
  2005. * old asm moved to oldasm/
  2006. Revision 1.133 1999/04/28 11:12:03 peter
  2007. * fixed crash with self pointer
  2008. Revision 1.132 1999/04/28 06:02:09 florian
  2009. * changes of Bruessel:
  2010. + message handler can now take an explicit self
  2011. * typinfo fixed: sometimes the type names weren't written
  2012. * the type checking for pointer comparisations and subtraction
  2013. and are now more strict (was also buggy)
  2014. * small bug fix to link.pas to support compiling on another
  2015. drive
  2016. * probable bug in popt386 fixed: call/jmp => push/jmp
  2017. transformation didn't count correctly the jmp references
  2018. + threadvar support
  2019. * warning if ln/sqrt gets an invalid constant argument
  2020. Revision 1.131 1999/04/26 13:31:44 peter
  2021. * release storenumber,double_checksum
  2022. Revision 1.130 1999/04/21 09:43:49 peter
  2023. * storenumber works
  2024. * fixed some typos in double_checksum
  2025. + incompatible types type1 and type2 message (with storenumber)
  2026. Revision 1.129 1999/04/20 14:39:07 daniel
  2027. *** empty log message ***
  2028. Revision 1.125 1999/04/14 09:14:55 peter
  2029. * first things to store the symbol/def number in the ppu
  2030. Revision 1.124 1999/04/07 15:31:13 pierre
  2031. * all formaldefs are now a sinlge definition
  2032. cformaldef (this was necessary for double_checksum)
  2033. + small part of double_checksum code
  2034. Revision 1.123 1999/04/06 11:21:58 peter
  2035. * more use of ttoken
  2036. Revision 1.122 1999/03/31 13:55:16 peter
  2037. * assembler inlining working for ag386bin
  2038. Revision 1.121 1999/03/26 00:05:39 peter
  2039. * released valintern
  2040. + deffile is now removed when compiling is finished
  2041. * ^( compiles now correct
  2042. + static directive
  2043. * shrd fixed
  2044. Revision 1.120 1999/03/24 23:17:18 peter
  2045. * fixed bugs 212,222,225,227,229,231,233
  2046. Revision 1.119 1999/03/05 09:46:18 pierre
  2047. * public problem for methods
  2048. Revision 1.118 1999/03/05 01:14:24 pierre
  2049. * bug0198 : call conventions for methods
  2050. not yet implemented is the control of same calling convention
  2051. for virtual and child's virtual
  2052. * msgstr and msgint only created if message was found
  2053. who implemented this by the way ?
  2054. it leaks lots of plabels !!!! (check with heaptrc !)
  2055. Revision 1.117 1999/03/04 13:55:47 pierre
  2056. * some m68k fixes (still not compilable !)
  2057. * new(tobj) does not give warning if tobj has no VMT !
  2058. Revision 1.116 1999/03/01 15:40:52 peter
  2059. * external name <str> didn't concatexternal()
  2060. Revision 1.115 1999/03/01 13:31:58 pierre
  2061. * external used before implemented problem fixed
  2062. Revision 1.114 1999/02/24 00:59:15 peter
  2063. * small updates for ag386bin
  2064. Revision 1.113 1999/02/23 18:29:21 pierre
  2065. * win32 compilation error fix
  2066. + some work for local browser (not cl=omplete yet)
  2067. Revision 1.112 1999/02/22 13:07:03 pierre
  2068. + -b and -bl options work !
  2069. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  2070. is not enabled when quitting global section
  2071. * local vars and procedures are not yet stored into PPU
  2072. Revision 1.111 1999/02/22 02:15:33 peter
  2073. * updates for ag386bin
  2074. Revision 1.110 1999/02/16 12:23:19 pierre
  2075. * nested forward procedure bug solved
  2076. Revision 1.109 1999/02/15 10:07:06 pierre
  2077. * memory leaks due to last commit solved
  2078. Revision 1.108 1999/02/11 09:46:27 pierre
  2079. * fix for normal method calls inside static methods :
  2080. WARNING there were both parser and codegen errors !!
  2081. added static_call boolean to calln tree
  2082. Revision 1.107 1999/02/10 11:27:39 pierre
  2083. * overloaded function locals problem bug0213
  2084. Revision 1.106 1999/02/08 11:29:05 pierre
  2085. * fix for bug0214
  2086. several problems where combined
  2087. search_class_member did not set srsymtable
  2088. => in do_member_read the call node got a wrong symtable
  2089. in cg386cal the vmt was pushed twice without chacking if it exists
  2090. now %esi is set to zero and pushed if not vmt
  2091. (not very efficient but should work !)
  2092. Revision 1.105 1999/02/05 12:51:20 florian
  2093. + openstring id is now supported
  2094. Revision 1.104 1999/02/03 09:26:44 pierre
  2095. + better reference for args of procs
  2096. Revision 1.103 1999/02/02 11:04:37 florian
  2097. * class destructors fixed, class instances weren't disposed correctly
  2098. Revision 1.102 1999/01/21 22:10:46 peter
  2099. * fixed array of const
  2100. * generic platform independent high() support
  2101. Revision 1.101 1999/01/20 14:18:38 pierre
  2102. * bugs related to mangledname solved
  2103. - linux external without name
  2104. -external procs already used
  2105. (added count and is_used boolean fiels in tprocvar)
  2106. Revision 1.100 1999/01/20 10:20:19 peter
  2107. * don't make localvar copies for assembler procedures
  2108. Revision 1.99 1999/01/19 15:59:40 pierre
  2109. * fix for function a;
  2110. Revision 1.98 1999/01/19 12:16:07 peter
  2111. * NOPASS2 now calls firstpass
  2112. Revision 1.97 1999/01/14 11:35:30 daniel
  2113. * Fixed manglednames
  2114. Revision 1.96 1998/12/30 13:41:10 peter
  2115. * released valuepara
  2116. Revision 1.95 1998/12/30 10:36:39 michael
  2117. + Delphi also allows external in interface section
  2118. Revision 1.94 1998/12/29 18:48:26 jonas
  2119. + optimize pascal code surrounding assembler blocks
  2120. Revision 1.93 1998/12/28 15:44:49 peter
  2121. + NOPASS2 define
  2122. Revision 1.92 1998/12/11 00:03:39 peter
  2123. + globtype,tokens,version unit splitted from globals
  2124. Revision 1.91 1998/11/27 14:50:42 peter
  2125. + open strings, $P switch support
  2126. Revision 1.90 1998/11/18 17:45:27 peter
  2127. * fixes for VALUEPARA
  2128. Revision 1.89 1998/11/18 15:44:15 peter
  2129. * VALUEPARA for tp7 compatible value parameters
  2130. Revision 1.88 1998/11/16 15:40:30 pierre
  2131. * mangling name and -So bugs solved
  2132. Revision 1.87 1998/11/16 11:29:02 pierre
  2133. * stackcheck removed for i386_win32
  2134. * exportlist does not crash at least !!
  2135. (was need for tests dir !)z
  2136. Revision 1.86 1998/11/16 10:13:54 peter
  2137. * label defines are checked at the end of the proc
  2138. Revision 1.85 1998/11/13 15:40:26 pierre
  2139. + added -Se in Makefile cvstest target
  2140. + lexlevel cleanup
  2141. normal_function_level main_program_level and unit_init_level defined
  2142. * tins_cache grown to A_EMMS (gave range check error in asm readers)
  2143. (test added in code !)
  2144. * -Un option was wrong
  2145. * _FAIL and _SELF only keyword inside
  2146. constructors and methods respectively
  2147. Revision 1.84 1998/11/10 10:09:13 peter
  2148. * va_list -> array of const
  2149. Revision 1.83 1998/11/09 11:44:34 peter
  2150. + va_list for printf support
  2151. Revision 1.82 1998/10/29 11:35:53 florian
  2152. * some dll support for win32
  2153. * fixed assembler writing for PalmOS
  2154. Revision 1.81 1998/10/28 18:26:16 pierre
  2155. * removed some erros after other errors (introduced by useexcept)
  2156. * stabs works again correctly (for how long !)
  2157. Revision 1.80 1998/10/27 13:45:37 pierre
  2158. * classes get a vmt allways
  2159. * better error info (tried to remove
  2160. several error strings introduced by the tpexcept handling)
  2161. Revision 1.79 1998/10/23 00:09:43 peter
  2162. * fixed message for forward declaration
  2163. Revision 1.78 1998/10/20 13:10:37 peter
  2164. * fixed crash when aktprocsym<>procsym
  2165. Revision 1.77 1998/10/20 08:06:55 pierre
  2166. * several memory corruptions due to double freemem solved
  2167. => never use p^.loc.location:=p^.left^.loc.location;
  2168. + finally I added now by default
  2169. that ra386dir translates global and unit symbols
  2170. + added a first field in tsymtable and
  2171. a nextsym field in tsym
  2172. (this allows to obtain ordered type info for
  2173. records and objects in gdb !)
  2174. Revision 1.76 1998/10/19 08:55:02 pierre
  2175. * wrong stabs info corrected once again !!
  2176. + variable vmt offset with vmt field only if required
  2177. implemented now !!!
  2178. Revision 1.75 1998/10/16 08:51:48 peter
  2179. + target_os.stackalignment
  2180. + stack can be aligned at 2 or 4 byte boundaries
  2181. Revision 1.74 1998/10/14 20:39:21 florian
  2182. * syscall for PalmOs fixed
  2183. Revision 1.73 1998/10/12 12:20:56 pierre
  2184. + added tai_const_symbol_offset
  2185. for r : pointer = @var.field;
  2186. * better message for different arg names on implementation
  2187. of function
  2188. Revision 1.72 1998/10/08 23:29:03 peter
  2189. * -vu shows unit info, -vt shows tried/used files
  2190. Revision 1.71 1998/10/08 17:17:28 pierre
  2191. * current_module old scanner tagged as invalid if unit is recompiled
  2192. + added ppheap for better info on tracegetmem of heaptrc
  2193. (adds line column and file index)
  2194. * several memory leaks removed ith help of heaptrc !!
  2195. Revision 1.70 1998/10/08 13:48:49 peter
  2196. * fixed memory leaks for do nothing source
  2197. * fixed unit interdependency
  2198. Revision 1.69 1998/10/05 21:33:27 peter
  2199. * fixed 161,165,166,167,168
  2200. Revision 1.68 1998/09/29 11:31:30 florian
  2201. * better error recovering when the object type of procedure tobject.method
  2202. isn't found
  2203. Revision 1.67 1998/09/26 17:45:39 peter
  2204. + idtoken and only one token table
  2205. Revision 1.66 1998/09/24 23:49:16 peter
  2206. + aktmodeswitches
  2207. Revision 1.65 1998/09/24 11:08:14 florian
  2208. * small problem in _proc_header with array of const fixed:
  2209. getsymonlyin doesn't set srsym to nil
  2210. Revision 1.64 1998/09/23 15:39:12 pierre
  2211. * browser bugfixes
  2212. was adding a reference when looking for the symbol
  2213. if -bSYM_NAME was used
  2214. Revision 1.63 1998/09/22 17:13:50 pierre
  2215. + browsing updated and developed
  2216. records and objects fields are also stored
  2217. Revision 1.62 1998/09/22 15:37:21 peter
  2218. + array of const start
  2219. Revision 1.61 1998/09/21 08:45:20 pierre
  2220. + added vmt_offset in tobjectdef.write for fututre use
  2221. (first steps to have objects without vmt if no virtual !!)
  2222. + added fpu_used field for tabstractprocdef :
  2223. sets this level to 2 if the functions return with value in FPU
  2224. (is then set to correct value at parsing of implementation)
  2225. THIS MIGHT refuse some code with FPU expression too complex
  2226. that were accepted before and even in some cases
  2227. that don't overflow in fact
  2228. ( like if f : float; is a forward that finally in implementation
  2229. only uses one fpu register !!)
  2230. Nevertheless I think that it will improve security on
  2231. FPU operations !!
  2232. * most other changes only for UseBrowser code
  2233. (added symtable references for record and objects)
  2234. local switch for refs to args and local of each function
  2235. (static symtable still missing)
  2236. UseBrowser still not stable and probably broken by
  2237. the definition hash array !!
  2238. Revision 1.60 1998/09/17 09:42:42 peter
  2239. + pass_2 for cg386
  2240. * Message() -> CGMessage() for pass_1/pass_2
  2241. Revision 1.59 1998/09/15 14:05:25 jonas
  2242. * fixed optimizer incompatibilities with freelabel code in psub
  2243. Revision 1.58 1998/09/14 21:27:41 peter
  2244. - freelabel calls, becuase they are instable with -O2
  2245. Revision 1.57 1998/09/14 10:38:27 peter
  2246. * pd_alias now uses get_stringconst
  2247. Revision 1.56 1998/09/14 10:29:38 daniel
  2248. * Fixed memory leaks.
  2249. Revision 1.55 1998/09/09 11:50:56 pierre
  2250. * forward def are not put in record or objects
  2251. + added check for forwards also in record and objects
  2252. * dummy parasymtable for unit initialization removed from
  2253. symtable stack
  2254. Revision 1.54 1998/09/04 08:42:05 peter
  2255. * updated some error messages
  2256. Revision 1.53 1998/09/01 17:39:51 peter
  2257. + internal constant functions
  2258. Revision 1.52 1998/09/01 09:07:12 peter
  2259. * m68k fixes, splitted cg68k like cgi386
  2260. Revision 1.51 1998/09/01 07:54:21 pierre
  2261. * UseBrowser a little updated (might still be buggy !!)
  2262. * bug in psub.pas in function specifier removed
  2263. * stdcall allowed in interface and in implementation
  2264. (FPC will not yet complain if it is missing in either part
  2265. because stdcall is only a dummy !!)
  2266. Revision 1.50 1998/08/31 12:26:31 peter
  2267. * m68k and palmos updates from surebugfixes
  2268. Revision 1.49 1998/08/25 12:42:43 pierre
  2269. * CDECL changed to CVAR for variables
  2270. specifications are read in structures also
  2271. + started adding GPC compatibility mode ( option -Sp)
  2272. * names changed to lowercase
  2273. Revision 1.48 1998/08/21 08:43:30 pierre
  2274. * pocdecl and poclearstack are now different
  2275. external must but written as last specification
  2276. Revision 1.47 1998/08/20 09:26:44 pierre
  2277. + funcret setting in underproc testing
  2278. compile with _dTEST_FUNCRET
  2279. Revision 1.46 1998/08/19 18:04:55 peter
  2280. * fixed current_module^.in_implementation flag
  2281. Revision 1.45 1998/08/13 10:58:38 peter
  2282. * fixed function reading for -So which was not correct after my previous
  2283. fix for bug 147
  2284. Revision 1.44 1998/08/10 14:50:18 peter
  2285. + localswitches, moduleswitches, globalswitches splitting
  2286. Revision 1.43 1998/08/10 09:58:33 peter
  2287. * Fixed function b; in -So mode
  2288. Revision 1.42 1998/07/30 16:07:11 florian
  2289. * try ... expect <statement> end; works now
  2290. Revision 1.41 1998/07/23 19:31:19 jonas
  2291. * split the optimizer
  2292. Revision 1.40 1998/07/21 11:16:24 florian
  2293. * bug0147 fixed
  2294. Revision 1.39 1998/07/14 21:46:54 peter
  2295. * updated messages file
  2296. Revision 1.38 1998/07/14 14:46:57 peter
  2297. * released NEWINPUT
  2298. Revision 1.37 1998/07/10 13:12:53 peter
  2299. * carls patch
  2300. Revision 1.36 1998/07/10 13:06:53 michael
  2301. + Carls patch. Checked make cycle.
  2302. Revision 1.35 1998/07/10 00:00:01 peter
  2303. * fixed ttypesym bug finally
  2304. * fileinfo in the symtable and better using for unused vars
  2305. Revision 1.34 1998/07/07 11:20:05 peter
  2306. + NEWINPUT for a better inputfile and scanner object
  2307. Revision 1.33 1998/06/15 15:38:08 pierre
  2308. * small bug in systems.pas corrected
  2309. + operators in different units better hanlded
  2310. Revision 1.32 1998/06/13 00:10:13 peter
  2311. * working browser and newppu
  2312. * some small fixes against crashes which occured in bp7 (but not in
  2313. fpc?!)
  2314. Revision 1.31 1998/06/10 17:04:05 michael
  2315. + Fix for reading untyped const parameters
  2316. Revision 1.30 1998/06/09 16:01:50 pierre
  2317. + added procedure directive parsing for procvars
  2318. (accepted are popstack cdecl and pascal)
  2319. + added C vars with the following syntax
  2320. var C calias 'true_c_name';(can be followed by external)
  2321. reason is that you must add the Cprefix
  2322. which is target dependent
  2323. Revision 1.29 1998/06/08 22:59:51 peter
  2324. * smartlinking works for win32
  2325. * some defines to exclude some compiler parts
  2326. Revision 1.28 1998/06/08 13:13:45 pierre
  2327. + temporary variables now in temp_gen.pas unit
  2328. because it is processor independent
  2329. * mppc68k.bat modified to undefine i386 and support_mmx
  2330. (which are defaults for i386)
  2331. Revision 1.27 1998/06/05 17:47:30 peter
  2332. * some better uses clauses
  2333. Revision 1.26 1998/06/05 14:37:36 pierre
  2334. * fixes for inline for operators
  2335. * inline procedure more correctly restricted
  2336. Revision 1.25 1998/06/04 23:51:54 peter
  2337. * m68k compiles
  2338. + .def file creation moved to gendef.pas so it could also be used
  2339. for win32
  2340. Revision 1.24 1998/06/04 09:55:44 pierre
  2341. * demangled name of procsym reworked to become independant of the mangling scheme
  2342. Revision 1.23 1998/05/28 17:26:51 peter
  2343. * fixed -R switch, it didn't work after my previous akt/init patch
  2344. * fixed bugs 110,130,136
  2345. Revision 1.22 1998/05/28 14:40:27 peter
  2346. * fixes for newppu, remake3 works now with it
  2347. Revision 1.21 1998/05/23 01:21:25 peter
  2348. + aktasmmode, aktoptprocessor, aktoutputformat
  2349. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2350. + $LIBNAME to set the library name where the unit will be put in
  2351. * splitted cgi386 a bit (codeseg to large for bp7)
  2352. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2353. Revision 1.20 1998/05/21 19:33:34 peter
  2354. + better procedure directive handling and only one table
  2355. Revision 1.19 1998/05/20 09:42:36 pierre
  2356. + UseTokenInfo now default
  2357. * unit in interface uses and implementation uses gives error now
  2358. * only one error for unknown symbol (uses lastsymknown boolean)
  2359. the problem came from the label code !
  2360. + first inlined procedures and function work
  2361. (warning there might be allowed cases were the result is still wrong !!)
  2362. * UseBrower updated gives a global list of all position of all used symbols
  2363. with switch -gb
  2364. Revision 1.18 1998/05/11 13:07:56 peter
  2365. + $ifdef NEWPPU for the new ppuformat
  2366. + $define GDB not longer required
  2367. * removed all warnings and stripped some log comments
  2368. * no findfirst/findnext anymore to remove smartlink *.o files
  2369. Revision 1.17 1998/05/06 18:36:54 peter
  2370. * tai_section extended with code,data,bss sections and enumerated type
  2371. * ident 'compiled by FPC' moved to pmodules
  2372. * small fix for smartlink
  2373. Revision 1.16 1998/05/06 08:38:47 pierre
  2374. * better position info with UseTokenInfo
  2375. UseTokenInfo greatly simplified
  2376. + added check for changed tree after first time firstpass
  2377. (if we could remove all the cases were it happen
  2378. we could skip all firstpass if firstpasscount > 1)
  2379. Only with ExtDebug
  2380. Revision 1.15 1998/05/04 17:54:28 peter
  2381. + smartlinking works (only case jumptable left todo)
  2382. * redesign of systems.pas to support assemblers and linkers
  2383. + Unitname is now also in the PPU-file, increased version to 14
  2384. Revision 1.14 1998/05/01 09:01:24 florian
  2385. + correct semantics of private and protected
  2386. * small fix in variable scope:
  2387. a id can be used in a parameter list of a method, even it is used in
  2388. an anchestor class as field id
  2389. Revision 1.13 1998/04/30 15:59:42 pierre
  2390. * GDB works again better :
  2391. correct type info in one pass
  2392. + UseTokenInfo for better source position
  2393. * fixed one remaining bug in scanner for line counts
  2394. * several little fixes
  2395. Revision 1.12 1998/04/29 10:34:00 pierre
  2396. + added some code for ansistring (not complete nor working yet)
  2397. * corrected operator overloading
  2398. * corrected nasm output
  2399. + started inline procedures
  2400. + added starstarn : use ** for exponentiation (^ gave problems)
  2401. + started UseTokenInfo cond to get accurate positions
  2402. Revision 1.11 1998/04/27 23:10:28 peter
  2403. + new scanner
  2404. * $makelib -> if smartlink
  2405. * small filename fixes pmodule.setfilename
  2406. * moved import from files.pas -> import.pas
  2407. Revision 1.10 1998/04/21 10:16:48 peter
  2408. * patches from strasbourg
  2409. * objects is not used anymore in the fpc compiled version
  2410. Revision 1.9 1998/04/13 22:20:36 florian
  2411. + stricter checking for duplicate id, solves also bug0097
  2412. Revision 1.8 1998/04/13 21:15:42 florian
  2413. * error handling of pass_1 and cgi386 fixed
  2414. * the following bugs fixed: 0117, 0118, 0119 and 0129, 0122 was already
  2415. fixed, verified
  2416. Revision 1.7 1998/04/13 08:42:52 florian
  2417. * call by reference and call by value open arrays fixed
  2418. Revision 1.6 1998/04/10 15:39:48 florian
  2419. * more fixes to get classes.pas compiled
  2420. Revision 1.5 1998/04/10 14:41:43 peter
  2421. * removed some Hints
  2422. * small speed optimization for AsmLn
  2423. Revision 1.4 1998/04/08 16:58:05 pierre
  2424. * several bugfixes
  2425. ADD ADC and AND are also sign extended
  2426. nasm output OK (program still crashes at end
  2427. and creates wrong assembler files !!)
  2428. procsym types sym in tdef removed !!
  2429. }