psub.pas 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721
  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,oldquickexitlabel:Pasmlabel;
  1399. _class,hp:Pobjectdef;
  1400. { switches can change inside the procedure }
  1401. entryswitches, exitswitches : tlocalswitches;
  1402. { code for the subroutine as tree }
  1403. {$ifdef newcg}
  1404. code:pnode;
  1405. {$else newcg}
  1406. code:ptree;
  1407. {$endif newcg}
  1408. { size of the local strackframe }
  1409. stackframe:longint;
  1410. { true when no stackframe is required }
  1411. nostackframe:boolean;
  1412. { number of bytes which have to be cleared by RET }
  1413. parasize:longint;
  1414. { filepositions }
  1415. entrypos,
  1416. savepos,
  1417. exitpos : tfileposinfo;
  1418. begin
  1419. { calculate the lexical level }
  1420. inc(lexlevel);
  1421. if lexlevel>32 then
  1422. Message(parser_e_too_much_lexlevel);
  1423. { static is also important for local procedures !! }
  1424. if (po_staticmethod in aktprocsym^.definition^.procoptions) then
  1425. allow_only_static:=true
  1426. else if (lexlevel=normal_function_level) then
  1427. allow_only_static:=false;
  1428. { save old labels }
  1429. oldexitlabel:=aktexitlabel;
  1430. oldexit2label:=aktexit2label;
  1431. oldquickexitlabel:=quickexitlabel;
  1432. { get new labels }
  1433. getlabel(aktexitlabel);
  1434. getlabel(aktexit2label);
  1435. { exit for fail in constructors }
  1436. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1437. getlabel(quickexitlabel);
  1438. { reset break and continue labels }
  1439. in_except_block:=false;
  1440. aktbreaklabel:=nil;
  1441. aktcontinuelabel:=nil;
  1442. { insert symtables for the class, by only if it is no nested function }
  1443. if assigned(procinfo._class) and not(parent_has_class) then
  1444. begin
  1445. { insert them in the reverse order ! }
  1446. hp:=nil;
  1447. repeat
  1448. _class:=procinfo._class;
  1449. while _class^.childof<>hp do
  1450. _class:=_class^.childof;
  1451. hp:=_class;
  1452. _class^.symtable^.next:=symtablestack;
  1453. symtablestack:=_class^.symtable;
  1454. until hp=procinfo._class;
  1455. end;
  1456. { insert parasymtable in symtablestack}
  1457. { only if lexlevel > 1 !!! global symtable should be right after staticsymtazble
  1458. for checking of same names used in interface and implementation !! }
  1459. if lexlevel>=normal_function_level then
  1460. begin
  1461. aktprocsym^.definition^.parast^.next:=symtablestack;
  1462. symtablestack:=aktprocsym^.definition^.parast;
  1463. symtablestack^.symtablelevel:=lexlevel;
  1464. end;
  1465. { insert localsymtable in symtablestack}
  1466. aktprocsym^.definition^.localst^.next:=symtablestack;
  1467. symtablestack:=aktprocsym^.definition^.localst;
  1468. symtablestack^.symtablelevel:=lexlevel;
  1469. { constant symbols are inserted in this symboltable }
  1470. constsymtable:=symtablestack;
  1471. { reset the temporary memory }
  1472. cleartempgen;
  1473. {$ifdef newcg}
  1474. tg.usedinproc:=[];
  1475. {$else newcg}
  1476. { no registers are used }
  1477. usedinproc:=0;
  1478. {$endif newcg}
  1479. { save entry info }
  1480. entrypos:=aktfilepos;
  1481. entryswitches:=aktlocalswitches;
  1482. {$ifdef newcg}
  1483. { parse the code ... }
  1484. if (po_assembler in aktprocsym^.definition^.procoptions) then
  1485. code:=convtree2node(assembler_block)
  1486. else
  1487. code:=convtree2node(block(current_module^.islibrary));
  1488. {$else newcg}
  1489. { parse the code ... }
  1490. if (po_assembler in aktprocsym^.definition^.procoptions) then
  1491. code:=assembler_block
  1492. else
  1493. code:=block(current_module^.islibrary);
  1494. {$endif newcg}
  1495. { get a better entry point }
  1496. if assigned(code) then
  1497. entrypos:=code^.fileinfo;
  1498. { save exit info }
  1499. exitswitches:=aktlocalswitches;
  1500. exitpos:=last_endtoken_filepos;
  1501. { save current filepos }
  1502. savepos:=aktfilepos;
  1503. {When we are called to compile the body of a unit, aktprocsym should
  1504. point to the unit initialization. If the unit has no initialization,
  1505. aktprocsym=nil. But in that case code=nil. hus we should check for
  1506. code=nil, when we use aktprocsym.}
  1507. { set the framepointer to esp for assembler functions }
  1508. { but only if the are no local variables }
  1509. { already done in assembler_block }
  1510. {$ifdef newcg}
  1511. tg.setfirsttemp(procinfo.firsttemp);
  1512. {$else newcg}
  1513. setfirsttemp(procinfo.firsttemp);
  1514. {$endif newcg}
  1515. { ... and generate assembler }
  1516. { but set the right switches for entry !! }
  1517. aktlocalswitches:=entryswitches;
  1518. {$ifndef NOPASS2}
  1519. {$ifdef newcg}
  1520. tg.setfirsttemp(procinfo.firsttemp);
  1521. {$else newcg}
  1522. if assigned(code) then
  1523. generatecode(code);
  1524. {$endif newcg}
  1525. { set switches to status at end of procedure }
  1526. aktlocalswitches:=exitswitches;
  1527. if assigned(code) then
  1528. begin
  1529. aktprocsym^.definition^.code:=code;
  1530. { the procedure is now defined }
  1531. aktprocsym^.definition^.forwarddef:=false;
  1532. {$ifdef newcg}
  1533. aktprocsym^.definition^.usedregisters:=tg.usedinproc;
  1534. {$else newcg}
  1535. aktprocsym^.definition^.usedregisters:=usedinproc;
  1536. {$endif newcg}
  1537. end;
  1538. {$ifdef newcg}
  1539. stackframe:=tg.gettempsize;
  1540. {$else newcg}
  1541. stackframe:=gettempsize;
  1542. {$endif newcg}
  1543. { first generate entry code with the correct position and switches }
  1544. aktfilepos:=entrypos;
  1545. aktlocalswitches:=entryswitches;
  1546. {$ifdef newcg}
  1547. if assigned(code) then
  1548. cg^.g_entrycode(procinfo.aktentrycode,proc_names,make_global,stackframe,parasize,nostackframe,false);
  1549. {$else newcg}
  1550. if assigned(code) then
  1551. genentrycode(procinfo.aktentrycode,proc_names,make_global,stackframe,parasize,nostackframe,false);
  1552. {$endif newcg}
  1553. { now generate exit code with the correct position and switches }
  1554. aktfilepos:=exitpos;
  1555. aktlocalswitches:=exitswitches;
  1556. if assigned(code) then
  1557. begin
  1558. {$ifdef newcg}
  1559. cg^.g_exitcode(procinfo.aktexitcode,parasize,nostackframe,false);
  1560. {$else newcg}
  1561. genexitcode(procinfo.aktexitcode,parasize,nostackframe,false);
  1562. {$endif newcg}
  1563. procinfo.aktproccode^.insertlist(procinfo.aktentrycode);
  1564. procinfo.aktproccode^.concatlist(procinfo.aktexitcode);
  1565. {$ifdef i386}
  1566. {$ifndef NoOpt}
  1567. if (cs_optimize in aktglobalswitches) and
  1568. { do not optimize pure assembler procedures }
  1569. ((procinfo.flags and pi_is_assembler)=0) then
  1570. Optimize(procinfo.aktproccode);
  1571. {$endif NoOpt}
  1572. {$endif}
  1573. { save local data (casetable) also in the same file }
  1574. if assigned(procinfo.aktlocaldata) and
  1575. (not procinfo.aktlocaldata^.empty) then
  1576. begin
  1577. procinfo.aktproccode^.concat(new(pai_section,init(sec_data)));
  1578. procinfo.aktproccode^.concatlist(procinfo.aktlocaldata);
  1579. end;
  1580. { now we can insert a cut }
  1581. if (cs_smartlink in aktmoduleswitches) then
  1582. codesegment^.concat(new(pai_cut,init));
  1583. { add the procedure to the codesegment }
  1584. codesegment^.concatlist(procinfo.aktproccode);
  1585. end;
  1586. {$else}
  1587. if assigned(code) then
  1588. firstpass(code);
  1589. {$endif NOPASS2}
  1590. { ... remove symbol tables, for the browser leave the static table }
  1591. { if (cs_browser in aktmoduleswitches) and (symtablestack^.symtabletype=staticsymtable) then
  1592. symtablestack^.next:=symtablestack^.next^.next
  1593. else }
  1594. if lexlevel>=normal_function_level then
  1595. symtablestack:=symtablestack^.next^.next
  1596. else
  1597. symtablestack:=symtablestack^.next;
  1598. { ... check for unused symbols }
  1599. { but only if there is no asm block }
  1600. if assigned(code) then
  1601. begin
  1602. if (Errorcount=0) then
  1603. begin
  1604. aktprocsym^.definition^.localst^.check_forwards;
  1605. aktprocsym^.definition^.localst^.checklabels;
  1606. end;
  1607. if (procinfo.flags and pi_uses_asm)=0 then
  1608. begin
  1609. { not for unit init, becuase the var can be used in finalize,
  1610. it will be done in proc_unit }
  1611. if not(aktprocsym^.definition^.proctypeoption in [potype_unitinit,potype_unitfinalize]) then
  1612. aktprocsym^.definition^.localst^.allsymbolsused;
  1613. aktprocsym^.definition^.parast^.allsymbolsused;
  1614. end;
  1615. end;
  1616. { the local symtables can be deleted, but the parast }
  1617. { doesn't, (checking definitons when calling a }
  1618. { function }
  1619. { not for a inline procedure !! (PM) }
  1620. { at lexlevel = 1 localst is the staticsymtable itself }
  1621. { so no dispose here !! }
  1622. if assigned(code) and
  1623. not(cs_browser in aktmoduleswitches) and
  1624. not(pocall_inline in aktprocsym^.definition^.proccalloptions) then
  1625. begin
  1626. if lexlevel>=normal_function_level then
  1627. dispose(aktprocsym^.definition^.localst,done);
  1628. aktprocsym^.definition^.localst:=nil;
  1629. end;
  1630. { only now we can remove the temps }
  1631. resettempgen;
  1632. { remove code tree, if not inline procedure }
  1633. if assigned(code) and not(pocall_inline in aktprocsym^.definition^.proccalloptions) then
  1634. {$ifdef newcg}
  1635. dispose(code,done);
  1636. {$else newcg}
  1637. disposetree(code);
  1638. {$endif newcg}
  1639. { remove class member symbol tables }
  1640. while symtablestack^.symtabletype=objectsymtable do
  1641. symtablestack:=symtablestack^.next;
  1642. { restore filepos, the switches are already set }
  1643. aktfilepos:=savepos;
  1644. { free labels }
  1645. freelabel(aktexitlabel);
  1646. freelabel(aktexit2label);
  1647. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1648. freelabel(quickexitlabel);
  1649. { restore labels }
  1650. aktexitlabel:=oldexitlabel;
  1651. aktexit2label:=oldexit2label;
  1652. quickexitlabel:=oldquickexitlabel;
  1653. { reset to normal non static function }
  1654. if (lexlevel=normal_function_level) then
  1655. allow_only_static:=false;
  1656. { previous lexlevel }
  1657. dec(lexlevel);
  1658. end;
  1659. procedure parse_proc_directives(Anames:Pstringcontainer;var pdflags:word);
  1660. {
  1661. Parse the procedure directives. It does not matter if procedure directives
  1662. are written using ;procdir; or ['procdir'] syntax.
  1663. }
  1664. var
  1665. res : boolean;
  1666. begin
  1667. while token in [_ID,_LECKKLAMMER] do
  1668. begin
  1669. if try_to_consume(_LECKKLAMMER) then
  1670. begin
  1671. repeat
  1672. parse_proc_direc(Anames^,pdflags);
  1673. until not try_to_consume(_COMMA);
  1674. consume(_RECKKLAMMER);
  1675. { we always expect at least '[];' }
  1676. res:=true;
  1677. end
  1678. else
  1679. res:=parse_proc_direc(Anames^,pdflags);
  1680. { A procedure directive is always followed by a semicolon }
  1681. if res then
  1682. consume(_SEMICOLON)
  1683. else
  1684. break;
  1685. end;
  1686. end;
  1687. procedure parse_var_proc_directives(var sym : ptypesym);
  1688. var
  1689. anames : pstringcontainer;
  1690. pdflags : word;
  1691. oldsym : pprocsym;
  1692. begin
  1693. oldsym:=aktprocsym;
  1694. anames:=new(pstringcontainer,init);
  1695. pdflags:=pd_procvar;
  1696. { we create a temporary aktprocsym to read the directives }
  1697. aktprocsym:=new(pprocsym,init(sym^.name));
  1698. { aktprocsym^.definition:=pprocdef(sym^.definition);
  1699. this breaks the rule for TESTOBJEXT !! }
  1700. pabstractprocdef(aktprocsym^.definition):=pabstractprocdef(sym^.definition);
  1701. { names should never be used anyway }
  1702. inc(lexlevel);
  1703. parse_proc_directives(anames,pdflags);
  1704. dec(lexlevel);
  1705. aktprocsym^.definition:=nil;
  1706. dispose(aktprocsym,done);
  1707. dispose(anames,done);
  1708. aktprocsym:=oldsym;
  1709. end;
  1710. procedure parse_object_proc_directives(var sym : pprocsym);
  1711. var
  1712. anames : pstringcontainer;
  1713. pdflags : word;
  1714. begin
  1715. pdflags:=pd_object;
  1716. anames:=new(pstringcontainer,init);
  1717. inc(lexlevel);
  1718. parse_proc_directives(anames,pdflags);
  1719. dec(lexlevel);
  1720. dispose(anames,done);
  1721. if (po_containsself in aktprocsym^.definition^.procoptions) and
  1722. (([po_msgstr,po_msgint]*aktprocsym^.definition^.procoptions)=[]) then
  1723. Message(parser_e_self_in_non_message_handler);
  1724. end;
  1725. procedure checkvaluepara(p:pnamedindexobject);{$ifndef FPC}far;{$endif}
  1726. var
  1727. vs : pvarsym;
  1728. s : string;
  1729. begin
  1730. with pvarsym(p)^ do
  1731. begin
  1732. if copy(name,1,3)='val' then
  1733. begin
  1734. s:=Copy(name,4,255);
  1735. if not(po_assembler in aktprocsym^.definition^.procoptions) then
  1736. begin
  1737. vs:=new(Pvarsym,init(s,definition));
  1738. vs^.fileinfo:=fileinfo;
  1739. vs^.varspez:=varspez;
  1740. aktprocsym^.definition^.localst^.insert(vs);
  1741. vs^.islocalcopy:=true;
  1742. vs^.varstate:=vs_used;
  1743. localvarsym:=vs;
  1744. end
  1745. else
  1746. begin
  1747. aktprocsym^.definition^.parast^.rename(name,s);
  1748. end;
  1749. end;
  1750. end;
  1751. end;
  1752. procedure read_proc;
  1753. {
  1754. Parses the procedure directives, then parses the procedure body, then
  1755. generates the code for it
  1756. }
  1757. var
  1758. oldprefix : string;
  1759. oldprocsym : Pprocsym;
  1760. oldprocinfo : tprocinfo;
  1761. oldconstsymtable : Psymtable;
  1762. oldfilepos : tfileposinfo;
  1763. names : Pstringcontainer;
  1764. pdflags : word;
  1765. begin
  1766. { save old state }
  1767. oldprocsym:=aktprocsym;
  1768. oldprefix:=procprefix;
  1769. oldconstsymtable:=constsymtable;
  1770. oldprocinfo:=procinfo;
  1771. { create a new procedure }
  1772. new(names,init);
  1773. codegen_newprocedure;
  1774. with procinfo do
  1775. begin
  1776. parent:=@oldprocinfo;
  1777. { clear flags }
  1778. flags:=0;
  1779. { standard frame pointer }
  1780. framepointer:=frame_pointer;
  1781. funcret_is_valid:=false;
  1782. { is this a nested function of a method ? }
  1783. _class:=oldprocinfo._class;
  1784. end;
  1785. parse_proc_dec;
  1786. { set the default function options }
  1787. if parse_only then
  1788. begin
  1789. {$ifdef INCLUDEOK}
  1790. include(aktprocsym^.symoptions,sp_forwarddef);
  1791. {$else}
  1792. aktprocsym^.symoptions:=aktprocsym^.symoptions+[sp_forwarddef];
  1793. {$endif}
  1794. aktprocsym^.definition^.forwarddef:=true;
  1795. { set also the interface flag, for better error message when the
  1796. implementation doesn't much this header }
  1797. aktprocsym^.definition^.interfacedef:=true;
  1798. pdflags:=pd_interface;
  1799. end
  1800. else
  1801. begin
  1802. pdflags:=pd_body;
  1803. if current_module^.in_implementation then
  1804. pdflags:=pdflags or pd_implemen;
  1805. if (not current_module^.is_unit) or (cs_smartlink in aktmoduleswitches) then
  1806. pdflags:=pdflags or pd_global;
  1807. procinfo.exported:=false;
  1808. aktprocsym^.definition^.forwarddef:=false;
  1809. end;
  1810. { parse the directives that may follow }
  1811. inc(lexlevel);
  1812. parse_proc_directives(names,pdflags);
  1813. dec(lexlevel);
  1814. { set aktfilepos to the beginning of the function declaration }
  1815. oldfilepos:=aktfilepos;
  1816. aktfilepos:=aktprocsym^.definition^.fileinfo;
  1817. { search for forward declarations }
  1818. if not check_identical then
  1819. begin
  1820. { A method must be forward defined (in the object declaration) }
  1821. if assigned(procinfo._class) and (not assigned(oldprocinfo._class)) then
  1822. Message(parser_e_header_dont_match_any_member);
  1823. { Give a better error if there is a forward def in the interface and only
  1824. a single implementation }
  1825. if (not aktprocsym^.definition^.forwarddef) and
  1826. assigned(aktprocsym^.definition^.nextoverloaded) and
  1827. aktprocsym^.definition^.nextoverloaded^.forwarddef and
  1828. aktprocsym^.definition^.nextoverloaded^.interfacedef and
  1829. not(assigned(aktprocsym^.definition^.nextoverloaded^.nextoverloaded)) then
  1830. Message1(parser_e_header_dont_match_forward,aktprocsym^.demangledName)
  1831. else
  1832. begin
  1833. { check the global flag }
  1834. if (procinfo.flags and pi_is_global)<>0 then
  1835. Message(parser_e_overloaded_must_be_all_global);
  1836. end
  1837. end;
  1838. { set return type here, becuase the aktprocsym^.definition can be
  1839. changed by check_identical (PFV) }
  1840. procinfo.retdef:=aktprocsym^.definition^.retdef;
  1841. { pointer to the return value ? }
  1842. if ret_in_param(procinfo.retdef) then
  1843. begin
  1844. procinfo.retoffset:=procinfo.call_offset;
  1845. inc(procinfo.call_offset,target_os.size_of_pointer);
  1846. end;
  1847. { allows to access the parameters of main functions in nested functions }
  1848. aktprocsym^.definition^.parast^.address_fixup:=procinfo.call_offset;
  1849. { when it is a value para and it needs a local copy then rename
  1850. the parameter and insert a copy in the localst. This is not done
  1851. for assembler procedures }
  1852. if (not parse_only) and (not aktprocsym^.definition^.forwarddef) then
  1853. aktprocsym^.definition^.parast^.foreach({$ifndef TP}@{$endif}checkvaluepara);
  1854. { restore file pos }
  1855. aktfilepos:=oldfilepos;
  1856. { compile procedure when a body is needed }
  1857. if (pdflags and pd_body)<>0 then
  1858. begin
  1859. Message1(parser_p_procedure_start,aktprocsym^.demangledname);
  1860. names^.insert(aktprocsym^.definition^.mangledname);
  1861. { set _FAIL as keyword if constructor }
  1862. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1863. tokeninfo[_FAIL].keyword:=m_all;
  1864. if assigned(aktprocsym^.definition^._class) then
  1865. tokeninfo[_SELF].keyword:=m_all;
  1866. compile_proc_body(names^,((pdflags and pd_global)<>0),assigned(oldprocinfo._class));
  1867. { reset _FAIL as normal }
  1868. if (aktprocsym^.definition^.proctypeoption=potype_constructor) then
  1869. tokeninfo[_FAIL].keyword:=m_none;
  1870. if assigned(aktprocsym^.definition^._class) and (lexlevel=main_program_level) then
  1871. tokeninfo[_SELF].keyword:=m_none;
  1872. consume(_SEMICOLON);
  1873. end;
  1874. { close }
  1875. dispose(names,done);
  1876. codegen_doneprocedure;
  1877. { Restore old state }
  1878. constsymtable:=oldconstsymtable;
  1879. { from now on all refernece to mangledname means
  1880. that the function is already used }
  1881. aktprocsym^.definition^.count:=true;
  1882. aktprocsym:=oldprocsym;
  1883. procprefix:=oldprefix;
  1884. procinfo:=oldprocinfo;
  1885. opsym:=nil;
  1886. end;
  1887. end.
  1888. {
  1889. $Log$
  1890. Revision 1.14 1999-08-10 16:24:44 pierre
  1891. * linking to C code with cdecl;external; was broken
  1892. Revision 1.13 1999/08/10 12:37:44 pierre
  1893. + procsym field of tprocdef set
  1894. Revision 1.12 1999/08/05 16:53:06 peter
  1895. * V_Fatal=1, all other V_ are also increased
  1896. * Check for local procedure when assigning procvar
  1897. * fixed comment parsing because directives
  1898. * oldtp mode directives better supported
  1899. * added some messages to errore.msg
  1900. Revision 1.11 1999/08/04 13:03:01 jonas
  1901. * all tokens now start with an underscore
  1902. * PowerPC compiles!!
  1903. Revision 1.10 1999/08/04 00:23:20 florian
  1904. * renamed i386asm and i386base to cpuasm and cpubase
  1905. Revision 1.9 1999/08/03 22:03:05 peter
  1906. * moved bitmask constants to sets
  1907. * some other type/const renamings
  1908. Revision 1.8 1999/08/03 17:09:42 florian
  1909. * the alpha compiler can be compiled now
  1910. Revision 1.7 1999/08/02 21:29:01 florian
  1911. * the main branch psub.pas is now used for
  1912. newcg compiler
  1913. Revision 1.6 1999/07/27 23:42:16 peter
  1914. * indirect type referencing is now allowed
  1915. Revision 1.5 1999/07/26 09:42:15 florian
  1916. * bugs 494-496 fixed
  1917. Revision 1.4 1999/07/11 20:10:24 peter
  1918. * merged
  1919. Revision 1.3 1999/07/02 13:02:24 peter
  1920. * merged
  1921. Revision 1.2 1999/06/17 13:19:56 pierre
  1922. * merged from 0_99_12 branch
  1923. Revision 1.1.2.4 1999/07/11 20:07:39 peter
  1924. * message crash fixed
  1925. * no error if self is used with non-string message
  1926. Revision 1.1.2.3 1999/07/11 20:04:05 pierre
  1927. * fix for problem with external without parameters in Delphi mode
  1928. Revision 1.1.2.2 1999/07/02 12:59:52 peter
  1929. * fixed parsing of message directive
  1930. Revision 1.1.2.1 1999/06/17 12:44:47 pierre
  1931. * solve problems related to assignment overloading
  1932. * support Delphi syntax for operator
  1933. * avoid problems if local procedure in operator
  1934. Revision 1.1 1999/06/11 13:21:37 peter
  1935. * reinserted
  1936. Revision 1.153 1999/06/02 22:44:14 pierre
  1937. * previous wrong log corrected
  1938. Revision 1.152 1999/06/02 22:25:46 pierre
  1939. * changed $ifdef FPC @ into $ifndef TP
  1940. Revision 1.151 1999/06/01 22:47:06 pierre
  1941. * problem with static keyword solved
  1942. Revision 1.150 1999/06/01 14:45:53 peter
  1943. * @procvar is now always needed for FPC
  1944. Revision 1.149 1999/05/31 16:42:31 peter
  1945. * interfacedef flag for procdef if it's defined in the interface, to
  1946. make a difference with 'forward;' directive forwarddef. Fixes 253
  1947. Revision 1.148 1999/05/27 19:44:52 peter
  1948. * removed oldasm
  1949. * plabel -> pasmlabel
  1950. * -a switches to source writing automaticly
  1951. * assembler readers OOPed
  1952. * asmsymbol automaticly external
  1953. * jumptables and other label fixes for asm readers
  1954. Revision 1.147 1999/05/24 08:55:27 florian
  1955. * non working safecall directiv implemented, I don't know if we
  1956. need it
  1957. Revision 1.146 1999/05/23 18:42:11 florian
  1958. * better error recovering in typed constants
  1959. * some problems with arrays of const fixed, some problems
  1960. due my previous
  1961. - the location type of array constructor is now LOC_MEM
  1962. - the pushing of high fixed
  1963. - parameter copying fixed
  1964. - zero temp. allocation removed
  1965. * small problem in the assembler writers fixed:
  1966. ref to nil wasn't written correctly
  1967. Revision 1.145 1999/05/21 13:55:09 peter
  1968. * NEWLAB for label as symbol
  1969. Revision 1.144 1999/05/18 14:15:55 peter
  1970. * containsself fixes
  1971. * checktypes()
  1972. Revision 1.143 1999/05/17 21:57:13 florian
  1973. * new temporary ansistring handling
  1974. Revision 1.142 1999/05/17 15:06:38 pierre
  1975. * fixes for object type check
  1976. Revision 1.141 1999/05/13 21:59:39 peter
  1977. * removed oldppu code
  1978. * warning if objpas is loaded from uses
  1979. * first things for new deref writing
  1980. Revision 1.140 1999/05/12 22:36:12 florian
  1981. * override isn't allowed in objects!
  1982. Revision 1.139 1999/05/10 09:01:41 peter
  1983. * small message fixes
  1984. Revision 1.138 1999/05/09 12:46:24 peter
  1985. + hint where a duplicate sym is already defined
  1986. Revision 1.137 1999/05/08 19:48:45 peter
  1987. * better error message if declaration doesn't match forward
  1988. Revision 1.136 1999/05/08 15:26:15 peter
  1989. * print also manglednames when changed
  1990. Revision 1.135 1999/05/06 10:12:10 peter
  1991. * fixed operator result offset which destroyed parast^.datasize
  1992. Revision 1.134 1999/05/01 13:24:36 peter
  1993. * merged nasm compiler
  1994. * old asm moved to oldasm/
  1995. Revision 1.133 1999/04/28 11:12:03 peter
  1996. * fixed crash with self pointer
  1997. Revision 1.132 1999/04/28 06:02:09 florian
  1998. * changes of Bruessel:
  1999. + message handler can now take an explicit self
  2000. * typinfo fixed: sometimes the type names weren't written
  2001. * the type checking for pointer comparisations and subtraction
  2002. and are now more strict (was also buggy)
  2003. * small bug fix to link.pas to support compiling on another
  2004. drive
  2005. * probable bug in popt386 fixed: call/jmp => push/jmp
  2006. transformation didn't count correctly the jmp references
  2007. + threadvar support
  2008. * warning if ln/sqrt gets an invalid constant argument
  2009. Revision 1.131 1999/04/26 13:31:44 peter
  2010. * release storenumber,double_checksum
  2011. Revision 1.130 1999/04/21 09:43:49 peter
  2012. * storenumber works
  2013. * fixed some typos in double_checksum
  2014. + incompatible types type1 and type2 message (with storenumber)
  2015. Revision 1.129 1999/04/20 14:39:07 daniel
  2016. *** empty log message ***
  2017. Revision 1.125 1999/04/14 09:14:55 peter
  2018. * first things to store the symbol/def number in the ppu
  2019. Revision 1.124 1999/04/07 15:31:13 pierre
  2020. * all formaldefs are now a sinlge definition
  2021. cformaldef (this was necessary for double_checksum)
  2022. + small part of double_checksum code
  2023. Revision 1.123 1999/04/06 11:21:58 peter
  2024. * more use of ttoken
  2025. Revision 1.122 1999/03/31 13:55:16 peter
  2026. * assembler inlining working for ag386bin
  2027. Revision 1.121 1999/03/26 00:05:39 peter
  2028. * released valintern
  2029. + deffile is now removed when compiling is finished
  2030. * ^( compiles now correct
  2031. + static directive
  2032. * shrd fixed
  2033. Revision 1.120 1999/03/24 23:17:18 peter
  2034. * fixed bugs 212,222,225,227,229,231,233
  2035. Revision 1.119 1999/03/05 09:46:18 pierre
  2036. * public problem for methods
  2037. Revision 1.118 1999/03/05 01:14:24 pierre
  2038. * bug0198 : call conventions for methods
  2039. not yet implemented is the control of same calling convention
  2040. for virtual and child's virtual
  2041. * msgstr and msgint only created if message was found
  2042. who implemented this by the way ?
  2043. it leaks lots of plabels !!!! (check with heaptrc !)
  2044. Revision 1.117 1999/03/04 13:55:47 pierre
  2045. * some m68k fixes (still not compilable !)
  2046. * new(tobj) does not give warning if tobj has no VMT !
  2047. Revision 1.116 1999/03/01 15:40:52 peter
  2048. * external name <str> didn't concatexternal()
  2049. Revision 1.115 1999/03/01 13:31:58 pierre
  2050. * external used before implemented problem fixed
  2051. Revision 1.114 1999/02/24 00:59:15 peter
  2052. * small updates for ag386bin
  2053. Revision 1.113 1999/02/23 18:29:21 pierre
  2054. * win32 compilation error fix
  2055. + some work for local browser (not cl=omplete yet)
  2056. Revision 1.112 1999/02/22 13:07:03 pierre
  2057. + -b and -bl options work !
  2058. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  2059. is not enabled when quitting global section
  2060. * local vars and procedures are not yet stored into PPU
  2061. Revision 1.111 1999/02/22 02:15:33 peter
  2062. * updates for ag386bin
  2063. Revision 1.110 1999/02/16 12:23:19 pierre
  2064. * nested forward procedure bug solved
  2065. Revision 1.109 1999/02/15 10:07:06 pierre
  2066. * memory leaks due to last commit solved
  2067. Revision 1.108 1999/02/11 09:46:27 pierre
  2068. * fix for normal method calls inside static methods :
  2069. WARNING there were both parser and codegen errors !!
  2070. added static_call boolean to calln tree
  2071. Revision 1.107 1999/02/10 11:27:39 pierre
  2072. * overloaded function locals problem bug0213
  2073. Revision 1.106 1999/02/08 11:29:05 pierre
  2074. * fix for bug0214
  2075. several problems where combined
  2076. search_class_member did not set srsymtable
  2077. => in do_member_read the call node got a wrong symtable
  2078. in cg386cal the vmt was pushed twice without chacking if it exists
  2079. now %esi is set to zero and pushed if not vmt
  2080. (not very efficient but should work !)
  2081. Revision 1.105 1999/02/05 12:51:20 florian
  2082. + openstring id is now supported
  2083. Revision 1.104 1999/02/03 09:26:44 pierre
  2084. + better reference for args of procs
  2085. Revision 1.103 1999/02/02 11:04:37 florian
  2086. * class destructors fixed, class instances weren't disposed correctly
  2087. Revision 1.102 1999/01/21 22:10:46 peter
  2088. * fixed array of const
  2089. * generic platform independent high() support
  2090. Revision 1.101 1999/01/20 14:18:38 pierre
  2091. * bugs related to mangledname solved
  2092. - linux external without name
  2093. -external procs already used
  2094. (added count and is_used boolean fiels in tprocvar)
  2095. Revision 1.100 1999/01/20 10:20:19 peter
  2096. * don't make localvar copies for assembler procedures
  2097. Revision 1.99 1999/01/19 15:59:40 pierre
  2098. * fix for function a;
  2099. Revision 1.98 1999/01/19 12:16:07 peter
  2100. * NOPASS2 now calls firstpass
  2101. Revision 1.97 1999/01/14 11:35:30 daniel
  2102. * Fixed manglednames
  2103. Revision 1.96 1998/12/30 13:41:10 peter
  2104. * released valuepara
  2105. Revision 1.95 1998/12/30 10:36:39 michael
  2106. + Delphi also allows external in interface section
  2107. Revision 1.94 1998/12/29 18:48:26 jonas
  2108. + optimize pascal code surrounding assembler blocks
  2109. Revision 1.93 1998/12/28 15:44:49 peter
  2110. + NOPASS2 define
  2111. Revision 1.92 1998/12/11 00:03:39 peter
  2112. + globtype,tokens,version unit splitted from globals
  2113. Revision 1.91 1998/11/27 14:50:42 peter
  2114. + open strings, $P switch support
  2115. Revision 1.90 1998/11/18 17:45:27 peter
  2116. * fixes for VALUEPARA
  2117. Revision 1.89 1998/11/18 15:44:15 peter
  2118. * VALUEPARA for tp7 compatible value parameters
  2119. Revision 1.88 1998/11/16 15:40:30 pierre
  2120. * mangling name and -So bugs solved
  2121. Revision 1.87 1998/11/16 11:29:02 pierre
  2122. * stackcheck removed for i386_win32
  2123. * exportlist does not crash at least !!
  2124. (was need for tests dir !)z
  2125. Revision 1.86 1998/11/16 10:13:54 peter
  2126. * label defines are checked at the end of the proc
  2127. Revision 1.85 1998/11/13 15:40:26 pierre
  2128. + added -Se in Makefile cvstest target
  2129. + lexlevel cleanup
  2130. normal_function_level main_program_level and unit_init_level defined
  2131. * tins_cache grown to A_EMMS (gave range check error in asm readers)
  2132. (test added in code !)
  2133. * -Un option was wrong
  2134. * _FAIL and _SELF only keyword inside
  2135. constructors and methods respectively
  2136. Revision 1.84 1998/11/10 10:09:13 peter
  2137. * va_list -> array of const
  2138. Revision 1.83 1998/11/09 11:44:34 peter
  2139. + va_list for printf support
  2140. Revision 1.82 1998/10/29 11:35:53 florian
  2141. * some dll support for win32
  2142. * fixed assembler writing for PalmOS
  2143. Revision 1.81 1998/10/28 18:26:16 pierre
  2144. * removed some erros after other errors (introduced by useexcept)
  2145. * stabs works again correctly (for how long !)
  2146. Revision 1.80 1998/10/27 13:45:37 pierre
  2147. * classes get a vmt allways
  2148. * better error info (tried to remove
  2149. several error strings introduced by the tpexcept handling)
  2150. Revision 1.79 1998/10/23 00:09:43 peter
  2151. * fixed message for forward declaration
  2152. Revision 1.78 1998/10/20 13:10:37 peter
  2153. * fixed crash when aktprocsym<>procsym
  2154. Revision 1.77 1998/10/20 08:06:55 pierre
  2155. * several memory corruptions due to double freemem solved
  2156. => never use p^.loc.location:=p^.left^.loc.location;
  2157. + finally I added now by default
  2158. that ra386dir translates global and unit symbols
  2159. + added a first field in tsymtable and
  2160. a nextsym field in tsym
  2161. (this allows to obtain ordered type info for
  2162. records and objects in gdb !)
  2163. Revision 1.76 1998/10/19 08:55:02 pierre
  2164. * wrong stabs info corrected once again !!
  2165. + variable vmt offset with vmt field only if required
  2166. implemented now !!!
  2167. Revision 1.75 1998/10/16 08:51:48 peter
  2168. + target_os.stackalignment
  2169. + stack can be aligned at 2 or 4 byte boundaries
  2170. Revision 1.74 1998/10/14 20:39:21 florian
  2171. * syscall for PalmOs fixed
  2172. Revision 1.73 1998/10/12 12:20:56 pierre
  2173. + added tai_const_symbol_offset
  2174. for r : pointer = @var.field;
  2175. * better message for different arg names on implementation
  2176. of function
  2177. Revision 1.72 1998/10/08 23:29:03 peter
  2178. * -vu shows unit info, -vt shows tried/used files
  2179. Revision 1.71 1998/10/08 17:17:28 pierre
  2180. * current_module old scanner tagged as invalid if unit is recompiled
  2181. + added ppheap for better info on tracegetmem of heaptrc
  2182. (adds line column and file index)
  2183. * several memory leaks removed ith help of heaptrc !!
  2184. Revision 1.70 1998/10/08 13:48:49 peter
  2185. * fixed memory leaks for do nothing source
  2186. * fixed unit interdependency
  2187. Revision 1.69 1998/10/05 21:33:27 peter
  2188. * fixed 161,165,166,167,168
  2189. Revision 1.68 1998/09/29 11:31:30 florian
  2190. * better error recovering when the object type of procedure tobject.method
  2191. isn't found
  2192. Revision 1.67 1998/09/26 17:45:39 peter
  2193. + idtoken and only one token table
  2194. Revision 1.66 1998/09/24 23:49:16 peter
  2195. + aktmodeswitches
  2196. Revision 1.65 1998/09/24 11:08:14 florian
  2197. * small problem in _proc_header with array of const fixed:
  2198. getsymonlyin doesn't set srsym to nil
  2199. Revision 1.64 1998/09/23 15:39:12 pierre
  2200. * browser bugfixes
  2201. was adding a reference when looking for the symbol
  2202. if -bSYM_NAME was used
  2203. Revision 1.63 1998/09/22 17:13:50 pierre
  2204. + browsing updated and developed
  2205. records and objects fields are also stored
  2206. Revision 1.62 1998/09/22 15:37:21 peter
  2207. + array of const start
  2208. Revision 1.61 1998/09/21 08:45:20 pierre
  2209. + added vmt_offset in tobjectdef.write for fututre use
  2210. (first steps to have objects without vmt if no virtual !!)
  2211. + added fpu_used field for tabstractprocdef :
  2212. sets this level to 2 if the functions return with value in FPU
  2213. (is then set to correct value at parsing of implementation)
  2214. THIS MIGHT refuse some code with FPU expression too complex
  2215. that were accepted before and even in some cases
  2216. that don't overflow in fact
  2217. ( like if f : float; is a forward that finally in implementation
  2218. only uses one fpu register !!)
  2219. Nevertheless I think that it will improve security on
  2220. FPU operations !!
  2221. * most other changes only for UseBrowser code
  2222. (added symtable references for record and objects)
  2223. local switch for refs to args and local of each function
  2224. (static symtable still missing)
  2225. UseBrowser still not stable and probably broken by
  2226. the definition hash array !!
  2227. Revision 1.60 1998/09/17 09:42:42 peter
  2228. + pass_2 for cg386
  2229. * Message() -> CGMessage() for pass_1/pass_2
  2230. Revision 1.59 1998/09/15 14:05:25 jonas
  2231. * fixed optimizer incompatibilities with freelabel code in psub
  2232. Revision 1.58 1998/09/14 21:27:41 peter
  2233. - freelabel calls, becuase they are instable with -O2
  2234. Revision 1.57 1998/09/14 10:38:27 peter
  2235. * pd_alias now uses get_stringconst
  2236. Revision 1.56 1998/09/14 10:29:38 daniel
  2237. * Fixed memory leaks.
  2238. Revision 1.55 1998/09/09 11:50:56 pierre
  2239. * forward def are not put in record or objects
  2240. + added check for forwards also in record and objects
  2241. * dummy parasymtable for unit initialization removed from
  2242. symtable stack
  2243. Revision 1.54 1998/09/04 08:42:05 peter
  2244. * updated some error messages
  2245. Revision 1.53 1998/09/01 17:39:51 peter
  2246. + internal constant functions
  2247. Revision 1.52 1998/09/01 09:07:12 peter
  2248. * m68k fixes, splitted cg68k like cgi386
  2249. Revision 1.51 1998/09/01 07:54:21 pierre
  2250. * UseBrowser a little updated (might still be buggy !!)
  2251. * bug in psub.pas in function specifier removed
  2252. * stdcall allowed in interface and in implementation
  2253. (FPC will not yet complain if it is missing in either part
  2254. because stdcall is only a dummy !!)
  2255. Revision 1.50 1998/08/31 12:26:31 peter
  2256. * m68k and palmos updates from surebugfixes
  2257. Revision 1.49 1998/08/25 12:42:43 pierre
  2258. * CDECL changed to CVAR for variables
  2259. specifications are read in structures also
  2260. + started adding GPC compatibility mode ( option -Sp)
  2261. * names changed to lowercase
  2262. Revision 1.48 1998/08/21 08:43:30 pierre
  2263. * pocdecl and poclearstack are now different
  2264. external must but written as last specification
  2265. Revision 1.47 1998/08/20 09:26:44 pierre
  2266. + funcret setting in underproc testing
  2267. compile with _dTEST_FUNCRET
  2268. Revision 1.46 1998/08/19 18:04:55 peter
  2269. * fixed current_module^.in_implementation flag
  2270. Revision 1.45 1998/08/13 10:58:38 peter
  2271. * fixed function reading for -So which was not correct after my previous
  2272. fix for bug 147
  2273. Revision 1.44 1998/08/10 14:50:18 peter
  2274. + localswitches, moduleswitches, globalswitches splitting
  2275. Revision 1.43 1998/08/10 09:58:33 peter
  2276. * Fixed function b; in -So mode
  2277. Revision 1.42 1998/07/30 16:07:11 florian
  2278. * try ... expect <statement> end; works now
  2279. Revision 1.41 1998/07/23 19:31:19 jonas
  2280. * split the optimizer
  2281. Revision 1.40 1998/07/21 11:16:24 florian
  2282. * bug0147 fixed
  2283. Revision 1.39 1998/07/14 21:46:54 peter
  2284. * updated messages file
  2285. Revision 1.38 1998/07/14 14:46:57 peter
  2286. * released NEWINPUT
  2287. Revision 1.37 1998/07/10 13:12:53 peter
  2288. * carls patch
  2289. Revision 1.36 1998/07/10 13:06:53 michael
  2290. + Carls patch. Checked make cycle.
  2291. Revision 1.35 1998/07/10 00:00:01 peter
  2292. * fixed ttypesym bug finally
  2293. * fileinfo in the symtable and better using for unused vars
  2294. Revision 1.34 1998/07/07 11:20:05 peter
  2295. + NEWINPUT for a better inputfile and scanner object
  2296. Revision 1.33 1998/06/15 15:38:08 pierre
  2297. * small bug in systems.pas corrected
  2298. + operators in different units better hanlded
  2299. Revision 1.32 1998/06/13 00:10:13 peter
  2300. * working browser and newppu
  2301. * some small fixes against crashes which occured in bp7 (but not in
  2302. fpc?!)
  2303. Revision 1.31 1998/06/10 17:04:05 michael
  2304. + Fix for reading untyped const parameters
  2305. Revision 1.30 1998/06/09 16:01:50 pierre
  2306. + added procedure directive parsing for procvars
  2307. (accepted are popstack cdecl and pascal)
  2308. + added C vars with the following syntax
  2309. var C calias 'true_c_name';(can be followed by external)
  2310. reason is that you must add the Cprefix
  2311. which is target dependent
  2312. Revision 1.29 1998/06/08 22:59:51 peter
  2313. * smartlinking works for win32
  2314. * some defines to exclude some compiler parts
  2315. Revision 1.28 1998/06/08 13:13:45 pierre
  2316. + temporary variables now in temp_gen.pas unit
  2317. because it is processor independent
  2318. * mppc68k.bat modified to undefine i386 and support_mmx
  2319. (which are defaults for i386)
  2320. Revision 1.27 1998/06/05 17:47:30 peter
  2321. * some better uses clauses
  2322. Revision 1.26 1998/06/05 14:37:36 pierre
  2323. * fixes for inline for operators
  2324. * inline procedure more correctly restricted
  2325. Revision 1.25 1998/06/04 23:51:54 peter
  2326. * m68k compiles
  2327. + .def file creation moved to gendef.pas so it could also be used
  2328. for win32
  2329. Revision 1.24 1998/06/04 09:55:44 pierre
  2330. * demangled name of procsym reworked to become independant of the mangling scheme
  2331. Revision 1.23 1998/05/28 17:26:51 peter
  2332. * fixed -R switch, it didn't work after my previous akt/init patch
  2333. * fixed bugs 110,130,136
  2334. Revision 1.22 1998/05/28 14:40:27 peter
  2335. * fixes for newppu, remake3 works now with it
  2336. Revision 1.21 1998/05/23 01:21:25 peter
  2337. + aktasmmode, aktoptprocessor, aktoutputformat
  2338. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2339. + $LIBNAME to set the library name where the unit will be put in
  2340. * splitted cgi386 a bit (codeseg to large for bp7)
  2341. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2342. Revision 1.20 1998/05/21 19:33:34 peter
  2343. + better procedure directive handling and only one table
  2344. Revision 1.19 1998/05/20 09:42:36 pierre
  2345. + UseTokenInfo now default
  2346. * unit in interface uses and implementation uses gives error now
  2347. * only one error for unknown symbol (uses lastsymknown boolean)
  2348. the problem came from the label code !
  2349. + first inlined procedures and function work
  2350. (warning there might be allowed cases were the result is still wrong !!)
  2351. * UseBrower updated gives a global list of all position of all used symbols
  2352. with switch -gb
  2353. Revision 1.18 1998/05/11 13:07:56 peter
  2354. + $ifdef NEWPPU for the new ppuformat
  2355. + $define GDB not longer required
  2356. * removed all warnings and stripped some log comments
  2357. * no findfirst/findnext anymore to remove smartlink *.o files
  2358. Revision 1.17 1998/05/06 18:36:54 peter
  2359. * tai_section extended with code,data,bss sections and enumerated type
  2360. * ident 'compiled by FPC' moved to pmodules
  2361. * small fix for smartlink
  2362. Revision 1.16 1998/05/06 08:38:47 pierre
  2363. * better position info with UseTokenInfo
  2364. UseTokenInfo greatly simplified
  2365. + added check for changed tree after first time firstpass
  2366. (if we could remove all the cases were it happen
  2367. we could skip all firstpass if firstpasscount > 1)
  2368. Only with ExtDebug
  2369. Revision 1.15 1998/05/04 17:54:28 peter
  2370. + smartlinking works (only case jumptable left todo)
  2371. * redesign of systems.pas to support assemblers and linkers
  2372. + Unitname is now also in the PPU-file, increased version to 14
  2373. Revision 1.14 1998/05/01 09:01:24 florian
  2374. + correct semantics of private and protected
  2375. * small fix in variable scope:
  2376. a id can be used in a parameter list of a method, even it is used in
  2377. an anchestor class as field id
  2378. Revision 1.13 1998/04/30 15:59:42 pierre
  2379. * GDB works again better :
  2380. correct type info in one pass
  2381. + UseTokenInfo for better source position
  2382. * fixed one remaining bug in scanner for line counts
  2383. * several little fixes
  2384. Revision 1.12 1998/04/29 10:34:00 pierre
  2385. + added some code for ansistring (not complete nor working yet)
  2386. * corrected operator overloading
  2387. * corrected nasm output
  2388. + started inline procedures
  2389. + added starstarn : use ** for exponentiation (^ gave problems)
  2390. + started UseTokenInfo cond to get accurate positions
  2391. Revision 1.11 1998/04/27 23:10:28 peter
  2392. + new scanner
  2393. * $makelib -> if smartlink
  2394. * small filename fixes pmodule.setfilename
  2395. * moved import from files.pas -> import.pas
  2396. Revision 1.10 1998/04/21 10:16:48 peter
  2397. * patches from strasbourg
  2398. * objects is not used anymore in the fpc compiled version
  2399. Revision 1.9 1998/04/13 22:20:36 florian
  2400. + stricter checking for duplicate id, solves also bug0097
  2401. Revision 1.8 1998/04/13 21:15:42 florian
  2402. * error handling of pass_1 and cgi386 fixed
  2403. * the following bugs fixed: 0117, 0118, 0119 and 0129, 0122 was already
  2404. fixed, verified
  2405. Revision 1.7 1998/04/13 08:42:52 florian
  2406. * call by reference and call by value open arrays fixed
  2407. Revision 1.6 1998/04/10 15:39:48 florian
  2408. * more fixes to get classes.pas compiled
  2409. Revision 1.5 1998/04/10 14:41:43 peter
  2410. * removed some Hints
  2411. * small speed optimization for AsmLn
  2412. Revision 1.4 1998/04/08 16:58:05 pierre
  2413. * several bugfixes
  2414. ADD ADC and AND are also sign extended
  2415. nasm output OK (program still crashes at end
  2416. and creates wrong assembler files !!)
  2417. procsym types sym in tdef removed !!
  2418. }