pdecl.pas 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. Does declaration parsing for Free Pascal
  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 pdecl;
  19. interface
  20. uses
  21. globtype,tokens,globals,symtable;
  22. var
  23. { pointer to the last read type symbol, (for "forward" }
  24. { types) }
  25. lasttypesym : ptypesym;
  26. { hack, which allows to use the current parsed }
  27. { object type as function argument type }
  28. testcurobject : byte;
  29. curobjectname : stringid;
  30. { reads a string type with optional length }
  31. { and returns a pointer to the string }
  32. { definition }
  33. function stringtype : pdef;
  34. { reads a string, file type or a type id and returns a name and }
  35. { pdef }
  36. function single_type(var s : string) : pdef;
  37. { reads the declaration blocks }
  38. procedure read_declarations(islibrary : boolean);
  39. { reads declarations in the interface part of a unit }
  40. procedure read_interface_declarations;
  41. implementation
  42. uses
  43. cobjects,scanner,aasm,tree,pass_1,
  44. files,types,hcodegen,verbose,systems,import
  45. {$ifdef GDB}
  46. ,gdb
  47. {$endif GDB}
  48. { parser specific stuff }
  49. ,pbase,ptconst,pexpr,psub,pexports
  50. { processor specific stuff }
  51. {$ifdef i386}
  52. ,i386
  53. {$endif}
  54. {$ifdef m68k}
  55. ,m68k
  56. {$endif}
  57. ;
  58. function read_type(const name : stringid) : pdef;forward;
  59. { search in symtablestack used, but not defined type }
  60. procedure testforward_type(p : psym);{$ifndef FPC}far;{$endif}
  61. var
  62. reaktvarsymtable : psymtable;
  63. oldaktfilepos : tfileposinfo;
  64. begin
  65. if not(p^.typ=typesym) then
  66. exit;
  67. if ((p^.properties and sp_forwarddef)<>0) then
  68. begin
  69. oldaktfilepos:=aktfilepos;
  70. aktfilepos:=p^.fileinfo;
  71. Message1(sym_e_forward_type_not_resolved,p^.name);
  72. aktfilepos:=oldaktfilepos;
  73. { try to recover }
  74. ptypesym(p)^.definition:=generrordef;
  75. p^.properties:=p^.properties and (not sp_forwarddef);
  76. end
  77. else
  78. if (ptypesym(p)^.definition^.deftype in [recorddef,objectdef]) then
  79. begin
  80. if (ptypesym(p)^.definition^.deftype=recorddef) then
  81. reaktvarsymtable:=precdef(ptypesym(p)^.definition)^.symtable
  82. else
  83. reaktvarsymtable:=pobjectdef(ptypesym(p)^.definition)^.publicsyms;
  84. {$ifdef tp}
  85. reaktvarsymtable^.foreach(testforward_type);
  86. {$else}
  87. reaktvarsymtable^.foreach(@testforward_type);
  88. {$endif}
  89. end;
  90. end;
  91. procedure const_dec;
  92. var
  93. name : stringid;
  94. p : ptree;
  95. def : pdef;
  96. sym : psym;
  97. storetokenpos,filepos : tfileposinfo;
  98. old_block_type : tblock_type;
  99. ps : pconstset;
  100. pd : pbestreal;
  101. sp : pstring;
  102. begin
  103. consume(_CONST);
  104. old_block_type:=block_type;
  105. block_type:=bt_const;
  106. repeat
  107. name:=pattern;
  108. filepos:=tokenpos;
  109. consume(ID);
  110. case token of
  111. EQUAL:
  112. begin
  113. consume(EQUAL);
  114. p:=comp_expr(true);
  115. do_firstpass(p);
  116. storetokenpos:=tokenpos;
  117. tokenpos:=filepos;
  118. case p^.treetype of
  119. ordconstn:
  120. begin
  121. if is_constintnode(p) then
  122. symtablestack^.insert(new(pconstsym,init(name,constint,p^.value,nil)))
  123. else if is_constcharnode(p) then
  124. symtablestack^.insert(new(pconstsym,init(name,constchar,p^.value,nil)))
  125. else if is_constboolnode(p) then
  126. symtablestack^.insert(new(pconstsym,init(name,constbool,p^.value,nil)))
  127. else if p^.resulttype^.deftype=enumdef then
  128. symtablestack^.insert(new(pconstsym,init(name,constord,p^.value,p^.resulttype)))
  129. else if p^.resulttype^.deftype=pointerdef then
  130. symtablestack^.insert(new(pconstsym,init(name,constord,p^.value,p^.resulttype)))
  131. else internalerror(111);
  132. end;
  133. stringconstn:
  134. begin
  135. { value_str is disposed with p so I need a copy }
  136. getmem(sp,p^.length+1);
  137. move(p^.value_str^,sp^[1],p^.length);
  138. {$ifndef TP}
  139. {$ifopt H+}
  140. setlength(sp^,p^.length);
  141. {$else}
  142. sp^[0]:=chr(p^.length);
  143. {$endif}
  144. {$else}
  145. sp^[0]:=chr(p^.length);
  146. {$endif}
  147. symtablestack^.insert(new(pconstsym,init(name,conststring,longint(sp),nil)));
  148. end;
  149. realconstn :
  150. begin
  151. new(pd);
  152. pd^:=p^.value_real;
  153. symtablestack^.insert(new(pconstsym,init(name,constreal,longint(pd),nil)));
  154. end;
  155. setconstn :
  156. begin
  157. new(ps);
  158. ps^:=p^.value_set^;
  159. symtablestack^.insert(new(pconstsym,init(name,constset,longint(ps),p^.resulttype)));
  160. end;
  161. niln :
  162. begin
  163. symtablestack^.insert(new(pconstsym,init(name,constnil,0,p^.resulttype)));
  164. end;
  165. else
  166. Message(cg_e_illegal_expression);
  167. end;
  168. tokenpos:=storetokenpos;
  169. consume(SEMICOLON);
  170. disposetree(p);
  171. end;
  172. COLON:
  173. begin
  174. { set the blocktype first so a consume also supports a
  175. caret, to support const s : ^string = nil }
  176. block_type:=bt_type;
  177. consume(COLON);
  178. ignore_equal:=true;
  179. def:=read_type('');
  180. ignore_equal:=false;
  181. block_type:=bt_const;
  182. storetokenpos:=tokenpos;
  183. tokenpos:=filepos;
  184. sym:=new(ptypedconstsym,init(name,def));
  185. tokenpos:=storetokenpos;
  186. symtablestack^.insert(sym);
  187. consume(EQUAL);
  188. readtypedconst(def,ptypedconstsym(sym));
  189. consume(SEMICOLON);
  190. end;
  191. else consume(EQUAL);
  192. end;
  193. until token<>ID;
  194. block_type:=old_block_type;
  195. end;
  196. procedure label_dec;
  197. var
  198. hl : plabel;
  199. begin
  200. consume(_LABEL);
  201. if not(cs_support_goto in aktmoduleswitches) then
  202. Message(sym_e_goto_and_label_not_supported);
  203. repeat
  204. if not(token in [ID,INTCONST]) then
  205. consume(ID)
  206. else
  207. begin
  208. getlabel(hl);
  209. symtablestack^.insert(new(plabelsym,init(pattern,hl)));
  210. consume(token);
  211. end;
  212. if token<>SEMICOLON then consume(COMMA);
  213. until not(token in [ID,INTCONST]);
  214. consume(SEMICOLON);
  215. end;
  216. procedure read_var_decs(is_record,is_object:boolean);
  217. { reads the filed of a record into a }
  218. { symtablestack, if record=false }
  219. { variants are forbidden, so this procedure }
  220. { can be used to read object fields }
  221. { if absolute is true, ABSOLUTE and file }
  222. { types are allowed }
  223. { => the procedure is also used to read }
  224. { a sequence of variable declaration }
  225. var
  226. sc : pstringcontainer;
  227. s : stringid;
  228. old_block_type : tblock_type;
  229. declarepos,storetokenpos : tfileposinfo;
  230. symdone : boolean;
  231. { to handle absolute }
  232. abssym : pabsolutesym;
  233. l : longint;
  234. code : word;
  235. { c var }
  236. newtype : ptypesym;
  237. is_dll,
  238. is_gpc_name,is_cdecl,extern_aktvarsym,export_aktvarsym : boolean;
  239. dll_name,
  240. C_name : string;
  241. { case }
  242. p,casedef : pdef;
  243. { maxsize contains the max. size of a variant }
  244. { startvarrec contains the start of the variant part of a record }
  245. maxsize,startvarrec : longint;
  246. pt : ptree;
  247. begin
  248. old_block_type:=block_type;
  249. block_type:=bt_type;
  250. is_gpc_name:=false;
  251. { Force an expected ID error message }
  252. if not (token in [ID,_CASE,_END]) then
  253. consume(ID);
  254. { read vars }
  255. while (token=ID) and
  256. not(is_object and (idtoken in [_PUBLIC,_PRIVATE,_PUBLISHED,_PROTECTED])) do
  257. begin
  258. C_name:=orgpattern;
  259. sc:=idlist;
  260. consume(COLON);
  261. if (m_gpc in aktmodeswitches) and
  262. not(is_record or is_object) and
  263. (token=ID) and (orgpattern='__asmname__') then
  264. begin
  265. consume(ID);
  266. C_name:=pattern;
  267. if token=CCHAR then
  268. consume(CCHAR)
  269. else
  270. consume(CSTRING);
  271. Is_gpc_name:=true;
  272. end;
  273. p:=read_type('');
  274. symdone:=false;
  275. if is_gpc_name then
  276. begin
  277. storetokenpos:=tokenpos;
  278. s:=sc^.get_with_tokeninfo(tokenpos);
  279. if not sc^.empty then
  280. Message(parser_e_absolute_only_one_var);
  281. dispose(sc,done);
  282. aktvarsym:=new(pvarsym,init_C(s,target_os.Cprefix+C_name,p));
  283. tokenpos:=storetokenpos;
  284. aktvarsym^.var_options:=aktvarsym^.var_options or vo_is_external;
  285. externals^.concat(new(pai_external,init(aktvarsym^.mangledname,EXT_NEAR)));
  286. symtablestack^.insert(aktvarsym);
  287. symdone:=true;
  288. end;
  289. { check for absolute }
  290. if not symdone and
  291. (idtoken=_ABSOLUTE) and not(is_record or is_object) then
  292. begin
  293. consume(_ABSOLUTE);
  294. { only allowed for one var }
  295. s:=sc^.get_with_tokeninfo(declarepos);
  296. if not sc^.empty then
  297. Message(parser_e_absolute_only_one_var);
  298. dispose(sc,done);
  299. { parse the rest }
  300. if token=ID then
  301. begin
  302. getsym(pattern,true);
  303. consume(ID);
  304. { we should check the result type of srsym }
  305. if not (srsym^.typ in [varsym,typedconstsym]) then
  306. Message(parser_e_absolute_only_to_var_or_const);
  307. storetokenpos:=tokenpos;
  308. tokenpos:=declarepos;
  309. abssym:=new(pabsolutesym,init(s,p));
  310. abssym^.abstyp:=tovar;
  311. abssym^.ref:=srsym;
  312. tokenpos:=storetokenpos;
  313. symtablestack^.insert(abssym);
  314. end
  315. else
  316. if (token=CSTRING) or (token=CCHAR) then
  317. begin
  318. storetokenpos:=tokenpos;
  319. tokenpos:=declarepos;
  320. abssym:=new(pabsolutesym,init(s,p));
  321. s:=pattern;
  322. consume(token);
  323. abssym^.abstyp:=toasm;
  324. abssym^.asmname:=stringdup(s);
  325. tokenpos:=storetokenpos;
  326. symtablestack^.insert(abssym);
  327. end
  328. else
  329. { absolute address ?!? }
  330. if token=INTCONST then
  331. begin
  332. if (target_info.target=target_i386_go32v2) then
  333. begin
  334. storetokenpos:=tokenpos;
  335. tokenpos:=declarepos;
  336. abssym:=new(pabsolutesym,init(s,p));
  337. abssym^.abstyp:=toaddr;
  338. abssym^.absseg:=false;
  339. tokenpos:=storetokenpos;
  340. s:=pattern;
  341. consume(INTCONST);
  342. val(s,abssym^.address,code);
  343. if token=COLON then
  344. begin
  345. consume(token);
  346. s:=pattern;
  347. consume(INTCONST);
  348. val(s,l,code);
  349. abssym^.address:=abssym^.address shl 4+l;
  350. abssym^.absseg:=true;
  351. end;
  352. symtablestack^.insert(abssym);
  353. end
  354. else
  355. Message(parser_e_absolute_only_to_var_or_const);
  356. end
  357. else
  358. Message(parser_e_absolute_only_to_var_or_const);
  359. symdone:=true;
  360. end;
  361. { for a record there doesn't need to be a ; before the END or ) }
  362. if not((is_record or is_object) and (token in [_END,RKLAMMER])) then
  363. consume(SEMICOLON);
  364. { procvar handling }
  365. if (p^.deftype=procvardef) and (p^.sym=nil) then
  366. begin
  367. newtype:=new(ptypesym,init('unnamed',p));
  368. parse_var_proc_directives(newtype);
  369. newtype^.definition:=nil;
  370. p^.sym:=nil;
  371. dispose(newtype,done);
  372. end;
  373. { Check for variable directives }
  374. if not symdone and (token=ID) then
  375. begin
  376. { Check for C Variable declarations }
  377. if (m_cvar_support in aktmodeswitches) and
  378. not(is_record or is_object) and
  379. (idtoken in [_EXPORT,_EXTERNAL,_PUBLIC,_CVAR]) then
  380. begin
  381. { only allowed for one var }
  382. s:=sc^.get_with_tokeninfo(declarepos);
  383. if not sc^.empty then
  384. Message(parser_e_absolute_only_one_var);
  385. dispose(sc,done);
  386. { defaults }
  387. is_dll:=false;
  388. is_cdecl:=false;
  389. extern_aktvarsym:=false;
  390. export_aktvarsym:=false;
  391. { cdecl }
  392. if idtoken=_CVAR then
  393. begin
  394. consume(_CVAR);
  395. consume(SEMICOLON);
  396. is_cdecl:=true;
  397. C_name:=target_os.Cprefix+C_name;
  398. end;
  399. { external }
  400. if idtoken=_EXTERNAL then
  401. begin
  402. consume(_EXTERNAL);
  403. extern_aktvarsym:=true;
  404. end;
  405. { export }
  406. if idtoken in [_EXPORT,_PUBLIC] then
  407. begin
  408. consume(ID);
  409. if extern_aktvarsym then
  410. Message(parser_e_not_external_and_export)
  411. else
  412. export_aktvarsym:=true;
  413. end;
  414. { external and export need a name after when no cdecl is used }
  415. if not is_cdecl then
  416. begin
  417. { dll name ? }
  418. if (extern_aktvarsym) and (token=CSTRING) then
  419. begin
  420. is_dll:=true;
  421. dll_name:=pattern;
  422. consume(CSTRING);
  423. end;
  424. consume(_NAME);
  425. C_name:=pattern;
  426. { allow also char }
  427. if token=CCHAR then
  428. consume(CCHAR)
  429. else
  430. consume(CSTRING);
  431. end;
  432. { consume the ; when export or external is used }
  433. if extern_aktvarsym or export_aktvarsym then
  434. consume(SEMICOLON);
  435. { insert in the symtable }
  436. storetokenpos:=tokenpos;
  437. tokenpos:=declarepos;
  438. if is_dll then
  439. aktvarsym:=new(pvarsym,init_dll(s,p))
  440. else
  441. aktvarsym:=new(pvarsym,init_C(s,C_name,p));
  442. tokenpos:=storetokenpos;
  443. { set some vars options }
  444. if export_aktvarsym then
  445. inc(aktvarsym^.refs);
  446. if extern_aktvarsym then
  447. aktvarsym^.var_options:=aktvarsym^.var_options or vo_is_external;
  448. { insert in the stack/datasegment }
  449. symtablestack^.insert(aktvarsym);
  450. { now we can insert it in the import lib if its a dll, or
  451. add it to the externals }
  452. if extern_aktvarsym then
  453. begin
  454. if is_dll then
  455. begin
  456. if not(current_module^.uses_imports) then
  457. begin
  458. current_module^.uses_imports:=true;
  459. importlib^.preparelib(current_module^.modulename^);
  460. end;
  461. importlib^.importvariable(aktvarsym^.mangledname,dll_name,C_name)
  462. end
  463. else
  464. externals^.concat(new(pai_external,init(aktvarsym^.mangledname,EXT_NEAR)));
  465. end;
  466. symdone:=true;
  467. end
  468. else
  469. if (is_object) and (cs_static_keyword in aktglobalswitches) and (idtoken=_STATIC) then
  470. begin
  471. current_object_option:=current_object_option or sp_static;
  472. insert_syms(symtablestack,sc,p);
  473. current_object_option:=current_object_option - sp_static;
  474. consume(_STATIC);
  475. consume(SEMICOLON);
  476. symdone:=true;
  477. end;
  478. end;
  479. { insert it in the symtable, if not done yet }
  480. if not symdone then
  481. begin
  482. if (current_object_option=sp_published) and
  483. (not((p^.deftype=objectdef) and (pobjectdef(p)^.isclass))) then
  484. Message(parser_e_cant_publish_that);
  485. insert_syms(symtablestack,sc,p);
  486. end;
  487. end;
  488. { Check for Case }
  489. if is_record and (token=_CASE) then
  490. begin
  491. maxsize:=0;
  492. consume(_CASE);
  493. s:=pattern;
  494. getsym(s,false);
  495. { may be only a type: }
  496. if assigned(srsym) and (srsym^.typ in [typesym,unitsym]) then
  497. casedef:=read_type('')
  498. else
  499. begin
  500. consume(ID);
  501. consume(COLON);
  502. casedef:=read_type('');
  503. symtablestack^.insert(new(pvarsym,init(s,casedef)));
  504. end;
  505. if not is_ordinal(casedef) then
  506. Message(type_e_ordinal_expr_expected);
  507. consume(_OF);
  508. startvarrec:=symtablestack^.datasize;
  509. repeat
  510. repeat
  511. pt:=comp_expr(true);
  512. do_firstpass(pt);
  513. if not(pt^.treetype=ordconstn) then
  514. Message(cg_e_illegal_expression);
  515. disposetree(pt);
  516. if token=COMMA then
  517. consume(COMMA)
  518. else
  519. break;
  520. until false;
  521. consume(COLON);
  522. { read the vars }
  523. consume(LKLAMMER);
  524. if token<>RKLAMMER then
  525. read_var_decs(true,false);
  526. consume(RKLAMMER);
  527. { calculates maximal variant size }
  528. maxsize:=max(maxsize,symtablestack^.datasize);
  529. { the items of the next variant are overlayed }
  530. symtablestack^.datasize:=startvarrec;
  531. if (token<>_END) and (token<>RKLAMMER) then
  532. consume(SEMICOLON)
  533. else
  534. break;
  535. until (token=_END) or (token=RKLAMMER);
  536. { at last set the record size to that of the biggest variant }
  537. symtablestack^.datasize:=maxsize;
  538. end;
  539. block_type:=old_block_type;
  540. end;
  541. function stringtype : pdef;
  542. { reads a string type with optional length }
  543. { and returns a pointer to the string }
  544. { definition }
  545. var
  546. p : ptree;
  547. d : pdef;
  548. begin
  549. consume(_STRING);
  550. if token=LECKKLAMMER then
  551. begin
  552. consume(LECKKLAMMER);
  553. p:=comp_expr(true);
  554. do_firstpass(p);
  555. if not is_constintnode(p) then
  556. Message(cg_e_illegal_expression);
  557. if (p^.value<=0) then
  558. begin
  559. Message(parser_e_invalid_string_size);
  560. p^.value:=255;
  561. end;
  562. consume(RECKKLAMMER);
  563. if p^.value>255 then
  564. d:=new(pstringdef,longinit(p^.value))
  565. else
  566. if p^.value<>255 then
  567. d:=new(pstringdef,shortinit(p^.value))
  568. else
  569. d:=cshortstringdef;
  570. disposetree(p);
  571. end
  572. else
  573. begin
  574. if cs_ansistrings in aktlocalswitches then
  575. d:=cansistringdef
  576. else
  577. d:=cshortstringdef;
  578. end;
  579. stringtype:=d;
  580. end;
  581. function id_type(var s : string) : pdef;
  582. { reads a type definition and returns a pointer }
  583. { to a appropriating pdef, s gets the name of }
  584. { the type to allow name mangling }
  585. begin
  586. s:=pattern;
  587. consume(ID);
  588. { classes can be used also in classes }
  589. if (curobjectname=pattern) and aktobjectdef^.isclass then
  590. begin
  591. id_type:=aktobjectdef;
  592. exit;
  593. end;
  594. { objects can be parameters }
  595. if (testcurobject=2) and (curobjectname=pattern) then
  596. begin
  597. id_type:=aktobjectdef;
  598. exit;
  599. end;
  600. getsym(s,true);
  601. if assigned(srsym) then
  602. begin
  603. if srsym^.typ=unitsym then
  604. begin
  605. consume(POINT);
  606. getsymonlyin(punitsym(srsym)^.unitsymtable,pattern);
  607. s:=pattern;
  608. consume(ID);
  609. end;
  610. if srsym^.typ<>typesym then
  611. begin
  612. Message(type_e_type_id_expected);
  613. lasttypesym:=ptypesym(srsym);
  614. id_type:=generrordef;
  615. exit;
  616. end;
  617. if not forwardsallowed then
  618. testforward_type(srsym);
  619. end;
  620. lasttypesym:=ptypesym(srsym);
  621. id_type:=ptypesym(srsym)^.definition;
  622. end;
  623. function single_type(var s : string) : pdef;
  624. { reads a string, file type or a type id and returns a name and }
  625. { pdef }
  626. var
  627. hs : string;
  628. begin
  629. case token of
  630. _STRING:
  631. begin
  632. single_type:=stringtype;
  633. s:='STRING';
  634. lasttypesym:=nil;
  635. end;
  636. _FILE:
  637. begin
  638. consume(_FILE);
  639. if token=_OF then
  640. begin
  641. consume(_OF);
  642. single_type:=new(pfiledef,init(ft_typed,single_type(hs)));
  643. s:='FILE$OF$'+hs;
  644. end
  645. else
  646. begin
  647. { single_type:=new(pfiledef,init(ft_untyped,nil));}
  648. single_type:=cfiledef;
  649. s:='FILE';
  650. end;
  651. lasttypesym:=nil;
  652. end;
  653. else single_type:=id_type(s);
  654. end;
  655. end;
  656. function object_dec(const n : stringid;fd : pobjectdef) : pdef;
  657. { this function parses an object or class declaration }
  658. var
  659. actmembertype : symprop;
  660. there_is_a_destructor : boolean;
  661. is_a_class : boolean;
  662. childof : pobjectdef;
  663. aktclass : pobjectdef;
  664. procedure constructor_head;
  665. begin
  666. consume(_CONSTRUCTOR);
  667. { must be at same level as in implementation }
  668. inc(lexlevel);
  669. parse_proc_head(poconstructor);
  670. dec(lexlevel);
  671. if (cs_constructor_name in aktglobalswitches) and (aktprocsym^.name<>'INIT') then
  672. Message(parser_e_constructorname_must_be_init);
  673. aktclass^.options:=aktclass^.options or oo_hasconstructor;
  674. consume(SEMICOLON);
  675. begin
  676. if (aktclass^.options and oo_is_class)<>0 then
  677. begin
  678. { CLASS constructors return the created instance }
  679. aktprocsym^.definition^.retdef:=aktclass;
  680. end
  681. else
  682. begin
  683. { OBJECT constructors return a boolean }
  684. {$IfDef GDB}
  685. {GDB doesn't like unnamed types !}
  686. aktprocsym^.definition^.retdef:=
  687. globaldef('boolean');
  688. {$Else GDB}
  689. aktprocsym^.definition^.retdef:=
  690. new(porddef,init(bool8bit,0,1));
  691. {$Endif GDB}
  692. end;
  693. end;
  694. end;
  695. procedure property_dec;
  696. var
  697. sym : psym;
  698. propertyparas : pdefcoll;
  699. { returns the matching procedure to access a property }
  700. function get_procdef : pprocdef;
  701. var
  702. p : pprocdef;
  703. begin
  704. p:=pprocsym(sym)^.definition;
  705. get_procdef:=nil;
  706. while assigned(p) do
  707. begin
  708. if equal_paras(p^.para1,propertyparas,true) then
  709. break;
  710. p:=p^.nextoverloaded;
  711. end;
  712. get_procdef:=p;
  713. end;
  714. var
  715. hp2,datacoll : pdefcoll;
  716. p,p2 : ppropertysym;
  717. overriden : psym;
  718. hs : string;
  719. code : word;
  720. varspez : tvarspez;
  721. sc : pstringcontainer;
  722. hp : pdef;
  723. s : string;
  724. declarepos : tfileposinfo;
  725. pp : pprocdef;
  726. pt : ptree;
  727. propname : stringid;
  728. begin
  729. { check for a class }
  730. if (aktclass^.options and oo_is_class=0) then
  731. Message(parser_e_syntax_error);
  732. consume(_PROPERTY);
  733. propertyparas:=nil;
  734. datacoll:=nil;
  735. if token=ID then
  736. begin
  737. p:=new(ppropertysym,init(pattern));
  738. propname:=pattern;
  739. consume(ID);
  740. { property parameters ? }
  741. if token=LECKKLAMMER then
  742. begin
  743. if current_object_option=sp_published then
  744. Message(parser_e_cant_publish_that_property);
  745. { create a list of the parameters in propertyparas }
  746. consume(LECKKLAMMER);
  747. inc(testcurobject);
  748. repeat
  749. if token=_VAR then
  750. begin
  751. consume(_VAR);
  752. varspez:=vs_var;
  753. end
  754. else if token=_CONST then
  755. begin
  756. consume(_CONST);
  757. varspez:=vs_const;
  758. end
  759. else varspez:=vs_value;
  760. sc:=idlist;
  761. if token=COLON then
  762. begin
  763. consume(COLON);
  764. if token=_ARRAY then
  765. begin
  766. {
  767. if (varspez<>vs_const) and
  768. (varspez<>vs_var) then
  769. begin
  770. varspez:=vs_const;
  771. Message(parser_e_illegal_open_parameter);
  772. end;
  773. }
  774. consume(_ARRAY);
  775. consume(_OF);
  776. { define range and type of range }
  777. hp:=new(parraydef,init(0,-1,s32bitdef));
  778. { define field type }
  779. parraydef(hp)^.definition:=single_type(s);
  780. end
  781. else
  782. hp:=single_type(s);
  783. end
  784. else
  785. hp:=new(pformaldef,init);
  786. s:=sc^.get_with_tokeninfo(declarepos);
  787. while s<>'' do
  788. begin
  789. new(hp2);
  790. hp2^.paratyp:=varspez;
  791. hp2^.data:=hp;
  792. hp2^.next:=propertyparas;
  793. propertyparas:=hp2;
  794. s:=sc^.get_with_tokeninfo(declarepos);
  795. end;
  796. dispose(sc,done);
  797. if token=SEMICOLON then consume(SEMICOLON)
  798. else break;
  799. until false;
  800. dec(testcurobject);
  801. consume(RECKKLAMMER);
  802. end;
  803. { overriden property ? }
  804. { force property interface, if there is a property parameter }
  805. if (token=COLON) or assigned(propertyparas) then
  806. begin
  807. consume(COLON);
  808. p^.proptype:=single_type(hs);
  809. if (idtoken=_INDEX) then
  810. begin
  811. consume(_INDEX);
  812. p^.options:=p^.options or ppo_indexed;
  813. if token=INTCONST then
  814. val(pattern,p^.index,code);
  815. consume(INTCONST);
  816. { concat a longint to the para template }
  817. new(hp2);
  818. hp2^.paratyp:=vs_value;
  819. hp2^.data:=s32bitdef;
  820. hp2^.next:=propertyparas;
  821. propertyparas:=hp2;
  822. end;
  823. end
  824. else
  825. begin
  826. { do an property override }
  827. overriden:=search_class_member(aktclass,propname);
  828. if assigned(overriden) and (overriden^.typ=propertysym) then
  829. begin
  830. { take the whole info: }
  831. p^.options:=ppropertysym(overriden)^.options;
  832. p^.index:=ppropertysym(overriden)^.index;
  833. p^.proptype:=ppropertysym(overriden)^.proptype;
  834. p^.writeaccesssym:=ppropertysym(overriden)^.writeaccesssym;
  835. p^.readaccesssym:=ppropertysym(overriden)^.readaccesssym;
  836. p^.writeaccessdef:=ppropertysym(overriden)^.writeaccessdef;
  837. p^.readaccessdef:=ppropertysym(overriden)^.readaccessdef;
  838. p^.storedsym:=ppropertysym(overriden)^.storedsym;
  839. p^.storeddef:=ppropertysym(overriden)^.storeddef;
  840. p^.default:=ppropertysym(overriden)^.default;
  841. end
  842. else
  843. begin
  844. p^.proptype:=generrordef;
  845. message(parser_e_no_property_found_to_override);
  846. end;
  847. end;
  848. if (current_object_option=sp_published) and
  849. not(p^.proptype^.is_publishable) then
  850. Message(parser_e_cant_publish_that_property);
  851. { create data defcoll to allow correct parameter checks }
  852. new(datacoll);
  853. datacoll^.paratyp:=vs_value;
  854. datacoll^.data:=p^.proptype;
  855. datacoll^.next:=nil;
  856. if (idtoken=_READ) then
  857. begin
  858. consume(_READ);
  859. sym:=search_class_member(aktclass,pattern);
  860. if not(assigned(sym)) then
  861. Message1(sym_e_unknown_id,pattern)
  862. else
  863. begin
  864. { varsym aren't allowed for an indexed property
  865. or an property with parameters }
  866. if ((sym^.typ=varsym) and
  867. { not necessary, an index forces propertyparas
  868. to be assigned
  869. }
  870. { (((p^.options and ppo_indexed)<>0) or }
  871. assigned(propertyparas)) or
  872. not(sym^.typ in [varsym,procsym]) then
  873. Message(parser_e_ill_property_access_sym);
  874. { search the matching definition }
  875. if sym^.typ=procsym then
  876. begin
  877. pp:=get_procdef;
  878. if not(assigned(pp)) or
  879. not(is_equal(pp^.retdef,p^.proptype)) then
  880. Message(parser_e_ill_property_access_sym);
  881. p^.readaccessdef:=pp;
  882. end
  883. else if sym^.typ=varsym then
  884. begin
  885. if not(is_equal(pvarsym(sym)^.definition,
  886. p^.proptype)) then
  887. Message(parser_e_ill_property_access_sym);
  888. end;
  889. p^.readaccesssym:=sym;
  890. end;
  891. consume(ID);
  892. end;
  893. if (idtoken=_WRITE) then
  894. begin
  895. consume(_WRITE);
  896. sym:=search_class_member(aktclass,pattern);
  897. if not(assigned(sym)) then
  898. Message1(sym_e_unknown_id,pattern)
  899. else
  900. begin
  901. if ((sym^.typ=varsym) and
  902. assigned(propertyparas)) or
  903. not(sym^.typ in [varsym,procsym]) then
  904. Message(parser_e_ill_property_access_sym);
  905. { search the matching definition }
  906. if sym^.typ=procsym then
  907. begin
  908. { insert data entry to check access method }
  909. datacoll^.next:=propertyparas;
  910. propertyparas:=datacoll;
  911. pp:=get_procdef;
  912. { ... and remove it }
  913. propertyparas:=propertyparas^.next;
  914. datacoll^.next:=nil;
  915. if not(assigned(pp)) then
  916. Message(parser_e_ill_property_access_sym);
  917. p^.writeaccessdef:=pp;
  918. end
  919. else if sym^.typ=varsym then
  920. begin
  921. if not(is_equal(pvarsym(sym)^.definition,
  922. p^.proptype)) then
  923. Message(parser_e_ill_property_access_sym);
  924. end;
  925. p^.writeaccesssym:=sym;
  926. end;
  927. consume(ID);
  928. end;
  929. if (idtoken=_STORED) then
  930. begin
  931. consume(_STORED);
  932. Message(parser_w_stored_not_implemented);
  933. { !!!!!!!! }
  934. end;
  935. if (idtoken=_DEFAULT) then
  936. begin
  937. consume(_DEFAULT);
  938. if not(is_ordinal(p^.proptype) or
  939. ((p^.proptype^.deftype=setdef) and
  940. (psetdef(p^.proptype)^.settype=smallset)
  941. ) or
  942. assigned(propertyparas)
  943. ) then
  944. Message(parser_e_property_cant_have_a_default_value);
  945. pt:=comp_expr(true);
  946. pt:=gentypeconvnode(pt,p^.proptype);
  947. do_firstpass(pt);
  948. if not(is_constnode(pt)) then
  949. Message(parser_e_property_default_value_must_const);
  950. if pt^.treetype=setconstn then
  951. p^.default:=plongint(pt^.value_set)^
  952. else
  953. p^.default:=pt^.value;
  954. disposetree(pt);
  955. end
  956. else if (idtoken=_NODEFAULT) then
  957. begin
  958. consume(_NODEFAULT);
  959. p^.default:=0;
  960. end;
  961. symtablestack^.insert(p);
  962. { default property ? }
  963. consume(SEMICOLON);
  964. if (idtoken=_DEFAULT) then
  965. begin
  966. consume(_DEFAULT);
  967. p2:=search_default_property(aktclass);
  968. if assigned(p2) then
  969. message1(parser_e_only_one_default_property,
  970. pobjectdef(p2^.owner^.defowner)^.name^)
  971. else
  972. begin
  973. p^.options:=p^.options or ppo_defaultproperty;
  974. if not(assigned(propertyparas)) then
  975. message(parser_e_property_need_paras);
  976. end;
  977. consume(SEMICOLON);
  978. end;
  979. { clean up }
  980. if assigned(datacoll) then
  981. disposepdefcoll(datacoll);
  982. end
  983. else
  984. begin
  985. consume(ID);
  986. consume(SEMICOLON);
  987. end;
  988. if assigned(propertyparas) then
  989. disposepdefcoll(propertyparas);
  990. end;
  991. procedure destructor_head;
  992. begin
  993. consume(_DESTRUCTOR);
  994. inc(lexlevel);
  995. parse_proc_head(podestructor);
  996. dec(lexlevel);
  997. if (cs_constructor_name in aktglobalswitches) and (aktprocsym^.name<>'DONE') then
  998. Message(parser_e_destructorname_must_be_done);
  999. aktclass^.options:=aktclass^.options or oo_hasdestructor;
  1000. consume(SEMICOLON);
  1001. if assigned(aktprocsym^.definition^.para1) then
  1002. Message(parser_e_no_paras_for_destructor);
  1003. { no return value }
  1004. aktprocsym^.definition^.retdef:=voiddef;
  1005. end;
  1006. var
  1007. hs : string;
  1008. pcrd : pclassrefdef;
  1009. hp1 : pdef;
  1010. hfp : pforwardpointer;
  1011. oldprocsym : pprocsym;
  1012. oldparse_only : boolean;
  1013. classnamelabel : plabel;
  1014. storetypeforwardsallowed : boolean;
  1015. begin
  1016. {Nowadays aktprocsym may already have a value, so we need to save
  1017. it.}
  1018. oldprocsym:=aktprocsym;
  1019. { forward is resolved }
  1020. if assigned(fd) then
  1021. fd^.options:=fd^.options and not(oo_isforward);
  1022. there_is_a_destructor:=false;
  1023. actmembertype:=sp_public;
  1024. { objects and class types can't be declared local }
  1025. if (symtablestack^.symtabletype<>globalsymtable) and
  1026. (symtablestack^.symtabletype<>staticsymtable) then
  1027. Message(parser_e_no_local_objects);
  1028. storetypeforwardsallowed:=typecanbeforward;
  1029. if m_tp in aktmodeswitches then
  1030. typecanbeforward:=false;
  1031. { distinguish classes and objects }
  1032. if token=_OBJECT then
  1033. begin
  1034. is_a_class:=false;
  1035. consume(_OBJECT)
  1036. end
  1037. else
  1038. begin
  1039. is_a_class:=true;
  1040. consume(_CLASS);
  1041. if not(assigned(fd)) and (token=_OF) then
  1042. begin
  1043. { a hack, but it's easy to handle }
  1044. { class reference type }
  1045. consume(_OF);
  1046. if typecanbeforward then
  1047. forwardsallowed:=true;
  1048. hp1:=single_type(hs);
  1049. { accept hp1, if is a forward def ...}
  1050. if ((lasttypesym<>nil)
  1051. and ((lasttypesym^.properties and sp_forwarddef)<>0)) or
  1052. { or a class
  1053. (if the foward defined type is a class is checked, when
  1054. the forward is resolved)
  1055. }
  1056. ((hp1^.deftype=objectdef) and (
  1057. (pobjectdef(hp1)^.options and oo_is_class)<>0)) then
  1058. begin
  1059. pcrd:=new(pclassrefdef,init(hp1));
  1060. object_dec:=pcrd;
  1061. {I add big troubles here
  1062. with var p : ^byte in graph.putimage
  1063. because a save_forward was called and
  1064. no resolve forward
  1065. => so the definition was rewritten after
  1066. having been disposed !!
  1067. Strange problems appeared !!!!}
  1068. {Anyhow forwards should only be allowed
  1069. inside a type statement ??
  1070. don't you think so }
  1071. if (lasttypesym<>nil) and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  1072. begin
  1073. new(hfp);
  1074. hfp^.next:=lasttypesym^.forwardpointer;
  1075. hfp^.def:=ppointerdef(pcrd);
  1076. lasttypesym^.forwardpointer:=hfp;
  1077. end;
  1078. forwardsallowed:=false;
  1079. end
  1080. else
  1081. begin
  1082. Message(type_e_class_type_expected);
  1083. object_dec:=new(perrordef,init);
  1084. end;
  1085. exit;
  1086. end
  1087. { forward class }
  1088. else if not(assigned(fd)) and (token=SEMICOLON) then
  1089. begin
  1090. { also anonym objects aren't allow (o : object a : longint; end;) }
  1091. if n='' then
  1092. begin
  1093. Message(parser_f_no_anonym_objects)
  1094. end;
  1095. if n='TOBJECT' then
  1096. begin
  1097. aktclass:=new(pobjectdef,init(n,nil));
  1098. class_tobject:=aktclass;
  1099. end
  1100. else
  1101. aktclass:=new(pobjectdef,init(n,nil));
  1102. aktclass^.options:=aktclass^.options or oo_is_class or oo_isforward;
  1103. { all classes must have a vmt !! at offset zero }
  1104. if (aktclass^.options and oo_hasvmt)=0 then
  1105. aktclass^.insertvmt;
  1106. object_dec:=aktclass;
  1107. exit;
  1108. end;
  1109. end;
  1110. { also anonym objects aren't allow (o : object a : longint; end;) }
  1111. if n='' then
  1112. Message(parser_f_no_anonym_objects);
  1113. { read the parent class }
  1114. if token=LKLAMMER then
  1115. begin
  1116. consume(LKLAMMER);
  1117. { does not allow objects.tobject !! }
  1118. {if token<>ID then
  1119. consume(ID);
  1120. getsym(pattern,true);}
  1121. childof:=pobjectdef(id_type(pattern));
  1122. if (childof^.deftype<>objectdef) then
  1123. begin
  1124. Message(type_e_class_type_expected);
  1125. childof:=nil;
  1126. end
  1127. else
  1128. begin
  1129. { a mix of class and object isn't allowed }
  1130. if (((childof^.options and oo_is_class)<>0) and not is_a_class) or
  1131. (((childof^.options and oo_is_class)=0) and is_a_class) then
  1132. Message(parser_e_mix_of_classes_and_objects);
  1133. end;
  1134. if assigned(fd) then
  1135. begin
  1136. { the forward of the child must be resolved to get
  1137. correct field addresses
  1138. }
  1139. if (childof^.options and oo_isforward)<>0 then
  1140. Message1(parser_e_forward_declaration_must_be_resolved,childof^.name^);
  1141. aktclass:=fd;
  1142. { we must inherit several options !!
  1143. this was missing !!
  1144. all is now done in set_parent
  1145. including symtable datasize setting PM }
  1146. fd^.set_parent(childof);
  1147. end
  1148. else
  1149. aktclass:=new(pobjectdef,init(n,childof));
  1150. consume(RKLAMMER);
  1151. end
  1152. { if no parent class, then a class get tobject as parent }
  1153. else if is_a_class then
  1154. begin
  1155. { is the current class tobject? }
  1156. { so you could define your own tobject }
  1157. if n='TOBJECT' then
  1158. begin
  1159. if assigned(fd) then
  1160. aktclass:=fd
  1161. else
  1162. aktclass:=new(pobjectdef,init(n,nil));
  1163. class_tobject:=aktclass;
  1164. end
  1165. else
  1166. begin
  1167. childof:=class_tobject;
  1168. if assigned(fd) then
  1169. begin
  1170. { the forward of the child must be resolved to get
  1171. correct field addresses
  1172. }
  1173. if (childof^.options and oo_isforward)<>0 then
  1174. Message1(parser_e_forward_declaration_must_be_resolved,childof^.name^);
  1175. aktclass:=fd;
  1176. aktclass^.set_parent(childof);
  1177. end
  1178. else
  1179. begin
  1180. aktclass:=new(pobjectdef,init(n,childof));
  1181. aktclass^.set_parent(childof);
  1182. end;
  1183. end;
  1184. end
  1185. else
  1186. aktclass:=new(pobjectdef,init(n,nil));
  1187. { set the class attribute }
  1188. if is_a_class then
  1189. begin
  1190. aktclass^.options:=aktclass^.options or oo_is_class;
  1191. if (cs_generate_rtti in aktlocalswitches) or
  1192. (assigned(aktclass^.childof) and
  1193. ((aktclass^.childof^.options and oo_can_have_published)<>0)
  1194. ) then
  1195. aktclass^.options:=aktclass^.options or oo_can_have_published;
  1196. end;
  1197. aktobjectdef:=aktclass;
  1198. { default access is public }
  1199. actmembertype:=sp_public;
  1200. aktclass^.publicsyms^.next:=symtablestack;
  1201. symtablestack:=aktclass^.publicsyms;
  1202. procinfo._class:=aktclass;
  1203. testcurobject:=1;
  1204. curobjectname:=n;
  1205. { short class declaration ? }
  1206. if (not is_a_class) or (token<>SEMICOLON) then
  1207. begin
  1208. { Parse componenten }
  1209. repeat
  1210. if actmembertype=sp_private then
  1211. aktclass^.options:=aktclass^.options or oo_hasprivate;
  1212. if actmembertype=sp_protected then
  1213. aktclass^.options:=aktclass^.options or oo_hasprotected;
  1214. case token of
  1215. ID : begin
  1216. case idtoken of
  1217. _PRIVATE : begin
  1218. consume(_PRIVATE);
  1219. actmembertype:=sp_private;
  1220. current_object_option:=sp_private;
  1221. end;
  1222. _PROTECTED : begin
  1223. consume(_PROTECTED);
  1224. current_object_option:=sp_protected;
  1225. actmembertype:=sp_protected;
  1226. end;
  1227. _PUBLIC : begin
  1228. consume(_PUBLIC);
  1229. current_object_option:=sp_public;
  1230. actmembertype:=sp_public;
  1231. end;
  1232. _PUBLISHED : begin
  1233. if (aktclass^.options and oo_can_have_published)=0 then
  1234. Message(parser_e_cant_have_published);
  1235. consume(_PUBLISHED);
  1236. current_object_option:=sp_published;
  1237. actmembertype:=sp_published;
  1238. end;
  1239. else
  1240. read_var_decs(false,true);
  1241. end;
  1242. end;
  1243. _PROPERTY : property_dec;
  1244. _PROCEDURE,
  1245. _FUNCTION,
  1246. _CLASS : begin
  1247. oldparse_only:=parse_only;
  1248. parse_only:=true;
  1249. parse_proc_dec;
  1250. parse_only:=oldparse_only;
  1251. case idtoken of
  1252. _DYNAMIC,
  1253. _VIRTUAL : begin
  1254. if actmembertype=sp_private then
  1255. Message(parser_w_priv_meth_not_virtual);
  1256. consume(idtoken);
  1257. consume(SEMICOLON);
  1258. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1259. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1260. end;
  1261. _OVERRIDE : begin
  1262. consume(_OVERRIDE);
  1263. consume(SEMICOLON);
  1264. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1265. pooverridingmethod or povirtualmethod;
  1266. end;
  1267. end;
  1268. if idtoken=_abstract then
  1269. begin
  1270. if (aktprocsym^.definition^.options and povirtualmethod)<>0 then
  1271. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or poabstractmethod
  1272. else
  1273. Message(parser_e_only_virtual_methods_abstract);
  1274. consume(_ABSTRACT);
  1275. consume(SEMICOLON);
  1276. { the method is defined }
  1277. aktprocsym^.definition^.forwarddef:=false;
  1278. end;
  1279. if (cs_static_keyword in aktglobalswitches) and (idtoken=_STATIC) then
  1280. begin
  1281. consume(_STATIC);
  1282. consume(SEMICOLON);
  1283. aktprocsym^.properties:=aktprocsym^.properties or sp_static;
  1284. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or postaticmethod;
  1285. end;
  1286. end;
  1287. _CONSTRUCTOR : begin
  1288. if actmembertype<>sp_public then
  1289. Message(parser_w_constructor_should_be_public);
  1290. oldparse_only:=parse_only;
  1291. parse_only:=true;
  1292. constructor_head;
  1293. parse_only:=oldparse_only;
  1294. case idtoken of
  1295. _DYNAMIC,
  1296. _VIRTUAL : begin
  1297. if not(aktclass^.isclass) then
  1298. Message(parser_e_constructor_cannot_be_not_virtual)
  1299. else
  1300. begin
  1301. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1302. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1303. end;
  1304. consume(idtoken);
  1305. consume(SEMICOLON);
  1306. end;
  1307. _OVERRIDE : begin
  1308. if (aktclass^.options and oo_is_class=0) then
  1309. Message(parser_e_constructor_cannot_be_not_virtual)
  1310. else
  1311. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1312. pooverridingmethod or povirtualmethod;
  1313. consume(_OVERRIDE);
  1314. consume(SEMICOLON);
  1315. end;
  1316. end;
  1317. end;
  1318. _DESTRUCTOR : begin
  1319. if there_is_a_destructor then
  1320. Message(parser_n_only_one_destructor);
  1321. there_is_a_destructor:=true;
  1322. if actmembertype<>sp_public then
  1323. Message(parser_w_destructor_should_be_public);
  1324. oldparse_only:=parse_only;
  1325. parse_only:=true;
  1326. destructor_head;
  1327. parse_only:=oldparse_only;
  1328. case idtoken of
  1329. _DYNAMIC,
  1330. _VIRTUAL : begin
  1331. consume(idtoken);
  1332. consume(SEMICOLON);
  1333. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or povirtualmethod;
  1334. aktclass^.options:=aktclass^.options or oo_hasvirtual;
  1335. end;
  1336. _OVERRIDE : begin
  1337. consume(_OVERRIDE);
  1338. consume(SEMICOLON);
  1339. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or
  1340. pooverridingmethod or povirtualmethod;
  1341. end;
  1342. end;
  1343. end;
  1344. _END : begin
  1345. consume(_END);
  1346. break;
  1347. end;
  1348. else
  1349. consume(ID); { Give a ident expected message, like tp7 }
  1350. end;
  1351. until false;
  1352. current_object_option:=sp_public;
  1353. end;
  1354. testcurobject:=0;
  1355. curobjectname:='';
  1356. typecanbeforward:=storetypeforwardsallowed;
  1357. { generate vmt space if needed }
  1358. if ((aktclass^.options and
  1359. (oo_hasvirtual or oo_hasconstructor or
  1360. oo_hasdestructor or oo_is_class))<>0) and
  1361. ((aktclass^.options and
  1362. oo_hasvmt)=0) then
  1363. aktclass^.insertvmt;
  1364. if (cs_smartlink in aktmoduleswitches) then
  1365. datasegment^.concat(new(pai_cut,init));
  1366. { write extended info for classes }
  1367. if is_a_class then
  1368. begin
  1369. if (aktclass^.options and oo_can_have_published)<>0 then
  1370. aktclass^.generate_rtti;
  1371. { write class name }
  1372. getlabel(classnamelabel);
  1373. datasegment^.concat(new(pai_label,init(classnamelabel)));
  1374. datasegment^.concat(new(pai_const,init_8bit(length(aktclass^.name^))));
  1375. datasegment^.concat(new(pai_string,init(aktclass^.name^)));
  1376. { interface table }
  1377. datasegment^.concat(new(pai_const,init_32bit(0)));
  1378. { auto table }
  1379. datasegment^.concat(new(pai_const,init_32bit(0)));
  1380. { inittable for con-/destruction }
  1381. if aktclass^.needs_inittable then
  1382. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(aktclass^.get_inittable_label)))))
  1383. else
  1384. datasegment^.concat(new(pai_const,init_32bit(0)));
  1385. { pointer to type info of published section }
  1386. if (aktclass^.options and oo_can_have_published)<>0 then
  1387. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.rtti_name))))
  1388. else
  1389. datasegment^.concat(new(pai_const,init_32bit(0)));
  1390. { pointer to field table }
  1391. datasegment^.concat(new(pai_const,init_32bit(0)));
  1392. { pointer to method table }
  1393. datasegment^.concat(new(pai_const,init_32bit(0)));
  1394. { pointer to dynamic table }
  1395. datasegment^.concat(new(pai_const,init_32bit(0)));
  1396. { pointer to class name string }
  1397. datasegment^.concat(new(pai_const,init_symbol(strpnew(lab2str(classnamelabel)))));
  1398. end;
  1399. {$ifdef GDB}
  1400. { generate the VMT }
  1401. if (cs_debuginfo in aktmoduleswitches) and
  1402. ((aktclass^.options and oo_hasvmt)<>0) then
  1403. begin
  1404. do_count_dbx:=true;
  1405. if assigned(aktclass^.owner) and assigned(aktclass^.owner^.name) then
  1406. datasegment^.concat(new(pai_stabs,init(strpnew('"vmt_'+aktclass^.owner^.name^+n+':S'+
  1407. typeglobalnumber('__vtbl_ptr_type')+'",'+tostr(N_STSYM)+',0,0,'+aktclass^.vmt_mangledname))));
  1408. end;
  1409. {$endif GDB}
  1410. if ((aktclass^.options and oo_hasvmt)<>0) then
  1411. begin
  1412. datasegment^.concat(new(pai_symbol,init_global(aktclass^.vmt_mangledname)));
  1413. { determine the size with publicsyms^.datasize, because }
  1414. { size gives back 4 for classes }
  1415. datasegment^.concat(new(pai_const,init_32bit(aktclass^.publicsyms^.datasize)));
  1416. datasegment^.concat(new(pai_const,init_32bit(-aktclass^.publicsyms^.datasize)));
  1417. { write pointer to parent VMT, this isn't implemented in TP }
  1418. { but this is not used in FPC ? (PM) }
  1419. { it's not used yet, but the delphi-operators as and is need it (FK) }
  1420. { it is not written for parents that don't have any vmt !! }
  1421. if assigned(aktclass^.childof) and
  1422. ((aktclass^.childof^.options and oo_hasvmt)<>0) then
  1423. begin
  1424. datasegment^.concat(new(pai_const,init_symbol(strpnew(aktclass^.childof^.vmt_mangledname))));
  1425. if aktclass^.childof^.owner^.symtabletype=unitsymtable then
  1426. concat_external(aktclass^.childof^.vmt_mangledname,EXT_NEAR);
  1427. end
  1428. else
  1429. datasegment^.concat(new(pai_const,init_32bit(0)));
  1430. { this generates the entries }
  1431. genvmt(aktclass);
  1432. end;
  1433. { restore old state }
  1434. symtablestack:=symtablestack^.next;
  1435. procinfo._class:=nil;
  1436. aktobjectdef:=nil;
  1437. {Restore the aktprocsym.}
  1438. aktprocsym:=oldprocsym;
  1439. object_dec:=aktclass;
  1440. end;
  1441. { reads a record declaration }
  1442. function record_dec : pdef;
  1443. var
  1444. symtable : psymtable;
  1445. storetypeforwardsallowed : boolean;
  1446. begin
  1447. symtable:=new(psymtable,init(recordsymtable));
  1448. symtable^.next:=symtablestack;
  1449. symtablestack:=symtable;
  1450. consume(_RECORD);
  1451. storetypeforwardsallowed:=typecanbeforward;
  1452. if m_tp in aktmodeswitches then
  1453. typecanbeforward:=false;
  1454. read_var_decs(true,false);
  1455. { may be scale record size to a size of n*4 ? }
  1456. if ((symtablestack^.datasize mod aktpackrecords)<>0) then
  1457. inc(symtablestack^.datasize,aktpackrecords-(symtablestack^.datasize mod aktpackrecords));
  1458. consume(_END);
  1459. typecanbeforward:=storetypeforwardsallowed;
  1460. symtablestack:=symtable^.next;
  1461. record_dec:=new(precdef,init(symtable));
  1462. end;
  1463. { reads a type definition and returns a pointer to it }
  1464. function read_type(const name : stringid) : pdef;
  1465. function handle_procvar:Pprocvardef;
  1466. var
  1467. sc : pstringcontainer;
  1468. s : string;
  1469. p : pdef;
  1470. varspez : tvarspez;
  1471. procvardef : pprocvardef;
  1472. begin
  1473. procvardef:=new(pprocvardef,init);
  1474. if token=LKLAMMER then
  1475. begin
  1476. consume(LKLAMMER);
  1477. inc(testcurobject);
  1478. repeat
  1479. case token of
  1480. _VAR :
  1481. begin
  1482. consume(_VAR);
  1483. varspez:=vs_var;
  1484. end;
  1485. _CONST :
  1486. begin
  1487. consume(_CONST);
  1488. varspez:=vs_const;
  1489. end;
  1490. else
  1491. varspez:=vs_value;
  1492. end;
  1493. sc:=idlist;
  1494. if (token=COLON) or (varspez=vs_value) then
  1495. begin
  1496. consume(COLON);
  1497. if token=_ARRAY then
  1498. begin
  1499. consume(_ARRAY);
  1500. consume(_OF);
  1501. { define range and type of range }
  1502. p:=new(Parraydef,init(0,-1,s32bitdef));
  1503. { array of const ? }
  1504. if (token=_CONST) and (m_objpas in aktmodeswitches) then
  1505. begin
  1506. consume(_CONST);
  1507. srsym:=nil;
  1508. if assigned(objpasunit) then
  1509. getsymonlyin(objpasunit,'TVARREC');
  1510. if not assigned(srsym) then
  1511. InternalError(1234124);
  1512. Parraydef(p)^.definition:=ptypesym(srsym)^.definition;
  1513. Parraydef(p)^.IsArrayOfConst:=true;
  1514. end
  1515. else
  1516. begin
  1517. { define field type }
  1518. Parraydef(p)^.definition:=single_type(s);
  1519. end;
  1520. end
  1521. else
  1522. p:=single_type(s);
  1523. end
  1524. else
  1525. p:=new(pformaldef,init);
  1526. while not sc^.empty do
  1527. begin
  1528. s:=sc^.get;
  1529. procvardef^.concatdef(p,varspez);
  1530. end;
  1531. dispose(sc,done);
  1532. if token=SEMICOLON then
  1533. consume(SEMICOLON)
  1534. else
  1535. break;
  1536. until false;
  1537. dec(testcurobject);
  1538. consume(RKLAMMER);
  1539. end;
  1540. handle_procvar:=procvardef;
  1541. end;
  1542. var
  1543. hp1,p : pdef;
  1544. aufdef : penumdef;
  1545. aufsym : penumsym;
  1546. ap : parraydef;
  1547. s : stringid;
  1548. l,v,oldaktpackrecords : longint;
  1549. hs : string;
  1550. procedure expr_type;
  1551. var
  1552. pt1,pt2 : ptree;
  1553. begin
  1554. { use of current parsed object ? }
  1555. if (token=ID) and (testcurobject=2) and (curobjectname=pattern) then
  1556. begin
  1557. consume(ID);
  1558. p:=aktobjectdef;
  1559. exit;
  1560. end;
  1561. { we can't accept a equal in type }
  1562. pt1:=comp_expr(not(ignore_equal));
  1563. do_firstpass(pt1);
  1564. if (token=POINTPOINT) then
  1565. begin
  1566. consume(POINTPOINT);
  1567. { get high value of range }
  1568. pt2:=comp_expr(not(ignore_equal));
  1569. do_firstpass(pt2);
  1570. { both must be evaluated to constants now }
  1571. if (pt1^.treetype<>ordconstn) or (pt2^.treetype<>ordconstn) then
  1572. Message(sym_e_error_in_type_def)
  1573. else
  1574. begin
  1575. { check types }
  1576. if not is_equal(pt1^.resulttype,pt2^.resulttype) then
  1577. Message(type_e_mismatch)
  1578. else
  1579. begin
  1580. { Check bounds }
  1581. if pt2^.value<pt1^.value then
  1582. Message(cg_e_upper_lower_than_lower)
  1583. else
  1584. begin
  1585. { All checks passed, create the new def }
  1586. case pt1^.resulttype^.deftype of
  1587. enumdef : p:=new(penumdef,init_subrange(penumdef(pt1^.resulttype),pt1^.value,pt2^.value));
  1588. orddef : begin
  1589. if is_char(pt1^.resulttype) then
  1590. p:=new(porddef,init(uchar,pt1^.value,pt2^.value))
  1591. else
  1592. if is_boolean(pt1^.resulttype) then
  1593. p:=new(porddef,init(bool8bit,pt1^.value,pt2^.value))
  1594. else
  1595. p:=new(porddef,init(uauto,pt1^.value,pt2^.value));
  1596. end;
  1597. end;
  1598. end;
  1599. end;
  1600. end;
  1601. disposetree(pt2);
  1602. end
  1603. else
  1604. begin
  1605. { a simple type renaming }
  1606. if (pt1^.treetype=typen) then
  1607. p:=pt1^.resulttype
  1608. else
  1609. Message(sym_e_error_in_type_def);
  1610. end;
  1611. disposetree(pt1);
  1612. end;
  1613. var
  1614. pt : ptree;
  1615. procedure array_dec;
  1616. var
  1617. lowval,
  1618. highval : longint;
  1619. arraytype : pdef;
  1620. begin
  1621. consume(_ARRAY);
  1622. consume(LECKKLAMMER);
  1623. { defaults }
  1624. arraytype:=generrordef;
  1625. lowval:=$80000000;
  1626. highval:=$7fffffff;
  1627. p:=nil;
  1628. repeat
  1629. { read the expression and check it }
  1630. pt:=expr;
  1631. if pt^.treetype=typen then
  1632. begin
  1633. case pt^.resulttype^.deftype of
  1634. enumdef : begin
  1635. lowval:=penumdef(pt^.resulttype)^.min;
  1636. highval:=penumdef(pt^.resulttype)^.max;
  1637. arraytype:=pt^.resulttype;
  1638. end;
  1639. orddef : begin
  1640. case porddef(pt^.resulttype)^.typ of
  1641. s8bit,u8bit,
  1642. s16bit,u16bit,
  1643. s32bit : begin
  1644. lowval:=porddef(pt^.resulttype)^.low;
  1645. highval:=porddef(pt^.resulttype)^.high;
  1646. arraytype:=pt^.resulttype;
  1647. end;
  1648. bool8bit,
  1649. bool16bit,
  1650. bool32bit : begin
  1651. lowval:=0;
  1652. highval:=1;
  1653. arraytype:=pt^.resulttype;
  1654. end;
  1655. uchar : begin
  1656. lowval:=0;
  1657. highval:=255;
  1658. arraytype:=pt^.resulttype;
  1659. end;
  1660. else
  1661. Message(sym_e_error_in_type_def);
  1662. end;
  1663. end;
  1664. else
  1665. Message(sym_e_error_in_type_def);
  1666. end
  1667. end
  1668. else
  1669. begin
  1670. do_firstpass(pt);
  1671. if (pt^.treetype=rangen) then
  1672. begin
  1673. if (pt^.left^.treetype=ordconstn) and
  1674. (pt^.right^.treetype=ordconstn) then
  1675. begin
  1676. lowval:=pt^.left^.value;
  1677. highval:=pt^.right^.value;
  1678. if highval<lowval then
  1679. begin
  1680. Message(parser_e_array_lower_less_than_upper_bound);
  1681. highval:=lowval;
  1682. end;
  1683. arraytype:=pt^.right^.resulttype;
  1684. end
  1685. else
  1686. Message(type_e_cant_eval_constant_expr);
  1687. end
  1688. else
  1689. Message(sym_e_error_in_type_def)
  1690. end;
  1691. disposetree(pt);
  1692. { create arraydef }
  1693. if p=nil then
  1694. begin
  1695. ap:=new(parraydef,init(lowval,highval,arraytype));
  1696. p:=ap;
  1697. end
  1698. else
  1699. begin
  1700. ap^.definition:=new(parraydef,init(lowval,highval,arraytype));
  1701. ap:=parraydef(ap^.definition);
  1702. end;
  1703. if token=COMMA then
  1704. consume(COMMA)
  1705. else
  1706. break;
  1707. until false;
  1708. consume(RECKKLAMMER);
  1709. consume(_OF);
  1710. hp1:=read_type('');
  1711. { if no error, set element type }
  1712. if assigned(ap) then
  1713. ap^.definition:=hp1;
  1714. end;
  1715. var
  1716. hfp : pforwardpointer;
  1717. begin
  1718. p:=nil;
  1719. case token of
  1720. _STRING,_FILE:
  1721. p:=single_type(hs);
  1722. LKLAMMER:
  1723. begin
  1724. consume(LKLAMMER);
  1725. { allow negativ value_str }
  1726. l:=-1;
  1727. aufsym := Nil;
  1728. aufdef:=new(penumdef,init);
  1729. repeat
  1730. s:=pattern;
  1731. consume(ID);
  1732. if token=ASSIGNMENT then
  1733. begin
  1734. consume(ASSIGNMENT);
  1735. v:=get_intconst;
  1736. { please leave that a note, allows type save }
  1737. { declarations in the win32 units ! }
  1738. if v<=l then
  1739. Message(parser_n_duplicate_enum);
  1740. l:=v;
  1741. end
  1742. else
  1743. inc(l);
  1744. constsymtable^.insert(new(penumsym,init(s,aufdef,l)));
  1745. if token=COMMA then
  1746. consume(COMMA)
  1747. else
  1748. break;
  1749. until false;
  1750. {aufdef^.max:=l;
  1751. if we allow unordered enums
  1752. this can be wrong
  1753. min and max are now set in tenumsym.init PM }
  1754. p:=aufdef;
  1755. consume(RKLAMMER);
  1756. end;
  1757. _ARRAY:
  1758. array_dec;
  1759. _SET:
  1760. begin
  1761. consume(_SET);
  1762. consume(_OF);
  1763. hp1:=read_type('');
  1764. if assigned(hp1) then
  1765. begin
  1766. case hp1^.deftype of
  1767. { don't forget that min can be negativ PM }
  1768. enumdef : if penumdef(hp1)^.min>=0 then
  1769. p:=new(psetdef,init(hp1,penumdef(hp1)^.max))
  1770. else
  1771. Message(sym_e_ill_type_decl_set);
  1772. orddef : begin
  1773. case porddef(hp1)^.typ of
  1774. uchar : p:=new(psetdef,init(hp1,255));
  1775. u8bit,s8bit,u16bit,s16bit,s32bit :
  1776. begin
  1777. if (porddef(hp1)^.low>=0) then
  1778. p:=new(psetdef,init(hp1,porddef(hp1)^.high))
  1779. else Message(sym_e_ill_type_decl_set);
  1780. end;
  1781. else Message(sym_e_ill_type_decl_set);
  1782. end;
  1783. end;
  1784. else Message(sym_e_ill_type_decl_set);
  1785. end;
  1786. end
  1787. else
  1788. p:=generrordef;
  1789. end;
  1790. CARET:
  1791. begin
  1792. consume(CARET);
  1793. { forwards allowed only inside TYPE statements }
  1794. if typecanbeforward then
  1795. forwardsallowed:=true;
  1796. hp1:=single_type(hs);
  1797. p:=new(ppointerdef,init(hp1));
  1798. {I add big troubles here
  1799. with var p : ^byte in graph.putimage
  1800. because a save_forward was called and
  1801. no resolve forward
  1802. => so the definition was rewritten after
  1803. having been disposed !!
  1804. Strange problems appeared !!!!}
  1805. {Anyhow forwards should only be allowed
  1806. inside a type statement ??
  1807. don't you think so }
  1808. if (lasttypesym<>nil) and ((lasttypesym^.properties and sp_forwarddef)<>0) then
  1809. begin
  1810. new(hfp);
  1811. hfp^.next:=lasttypesym^.forwardpointer;
  1812. hfp^.def:=ppointerdef(p);
  1813. lasttypesym^.forwardpointer:=hfp;
  1814. end;
  1815. forwardsallowed:=false;
  1816. end;
  1817. _RECORD:
  1818. p:=record_dec;
  1819. _PACKED:
  1820. begin
  1821. consume(_PACKED);
  1822. if token=_ARRAY then
  1823. array_dec
  1824. else
  1825. begin
  1826. oldaktpackrecords:=aktpackrecords;
  1827. aktpackrecords:=1;
  1828. if token in [_CLASS,_OBJECT] then
  1829. p:=object_dec(name,nil)
  1830. else
  1831. p:=record_dec;
  1832. aktpackrecords:=oldaktpackrecords;
  1833. end;
  1834. end;
  1835. _CLASS,
  1836. _OBJECT:
  1837. p:=object_dec(name,nil);
  1838. _PROCEDURE:
  1839. begin
  1840. consume(_PROCEDURE);
  1841. p:=handle_procvar;
  1842. if token=_OF then
  1843. begin
  1844. consume(_OF);
  1845. consume(_OBJECT);
  1846. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1847. end;
  1848. end;
  1849. _FUNCTION:
  1850. begin
  1851. consume(_FUNCTION);
  1852. p:=handle_procvar;
  1853. consume(COLON);
  1854. pprocvardef(p)^.retdef:=single_type(hs);
  1855. if token=_OF then
  1856. begin
  1857. consume(_OF);
  1858. consume(_OBJECT);
  1859. pprocvardef(p)^.options:=pprocvardef(p)^.options or pomethodpointer;
  1860. end;
  1861. end;
  1862. else
  1863. expr_type;
  1864. end;
  1865. if p=nil then
  1866. p:=generrordef;
  1867. read_type:=p;
  1868. end;
  1869. { reads a type declaration to the symbol table }
  1870. procedure type_dec;
  1871. var
  1872. typename : stringid;
  1873. newtype : ptypesym;
  1874. {$ifdef dummy}
  1875. olddef,newdef : pdef;
  1876. s : string;
  1877. {$endif dummy}
  1878. begin
  1879. block_type:=bt_type;
  1880. consume(_TYPE);
  1881. typecanbeforward:=true;
  1882. repeat
  1883. typename:=pattern;
  1884. consume(ID);
  1885. consume(EQUAL);
  1886. { here you loose the strictness of pascal
  1887. for which a redefinition like
  1888. childtype = parenttype;
  1889. child2type = parenttype;
  1890. does not make the two child types equal !!
  1891. here all vars from childtype and child2type
  1892. get the definition of parenttype !! }
  1893. {$ifdef testequaltype}
  1894. if (token = ID) or (token=_FILE) or (token=_STRING) then
  1895. begin
  1896. olddef := single_type(s);
  1897. { make a clone of olddef }
  1898. { is that ok ??? }
  1899. getmem(newdef,SizeOf(olddef));
  1900. move(olddef^,newdef^,SizeOf(olddef));
  1901. newtype:=new(ptypesym,init(typename,newdef));
  1902. symtablestack^.insert(newtype);
  1903. end
  1904. else
  1905. {$endif testequaltype}
  1906. begin
  1907. getsym(typename,false);
  1908. { check if it is the definition of a forward defined class }
  1909. if assigned(srsym) and (token=_CLASS) and
  1910. (srsym^.typ=typesym) and
  1911. (ptypesym(srsym)^.definition^.deftype=objectdef) and
  1912. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oo_isforward)<>0) and
  1913. ((pobjectdef(ptypesym(srsym)^.definition)^.options and oo_is_class)<>0) then
  1914. begin
  1915. { we can ignore the result }
  1916. { the definition is modified }
  1917. object_dec(typename,pobjectdef(ptypesym(srsym)^.definition));
  1918. newtype:=ptypesym(srsym);
  1919. end
  1920. else
  1921. begin
  1922. newtype:=new(ptypesym,init(typename,read_type(typename)));
  1923. { load newtype with the new pointer to the inserted type
  1924. because it can be an already defined forwarded type !! }
  1925. newtype:=ptypesym(symtablestack^.insert(newtype));
  1926. end;
  1927. end;
  1928. consume(SEMICOLON);
  1929. if assigned(newtype^.definition) and (newtype^.definition^.deftype=procvardef) then
  1930. parse_var_proc_directives(newtype);
  1931. until token<>ID;
  1932. typecanbeforward:=false;
  1933. {$ifdef tp}
  1934. symtablestack^.foreach(testforward_type);
  1935. {$else}
  1936. symtablestack^.foreach(@testforward_type);
  1937. {$endif}
  1938. resolve_forwards;
  1939. block_type:=bt_general;
  1940. end;
  1941. procedure var_dec;
  1942. { parses varaible declarations and inserts them in }
  1943. { the top symbol table of symtablestack }
  1944. begin
  1945. consume(_VAR);
  1946. read_var_decs(false,false);
  1947. end;
  1948. procedure Not_supported_for_inline(t : ttoken);
  1949. begin
  1950. if assigned(aktprocsym) and
  1951. ((aktprocsym^.definition^.options and poinline)<>0) then
  1952. Begin
  1953. Message1(parser_w_not_supported_for_inline,tokenstring(t));
  1954. Message(parser_w_inlining_disabled);
  1955. aktprocsym^.definition^.options:= aktprocsym^.definition^.options and not poinline;
  1956. End;
  1957. end;
  1958. procedure read_declarations(islibrary : boolean);
  1959. begin
  1960. repeat
  1961. case token of
  1962. _LABEL:
  1963. begin
  1964. Not_supported_for_inline(token);
  1965. label_dec;
  1966. end;
  1967. _CONST:
  1968. begin
  1969. Not_supported_for_inline(token);
  1970. const_dec;
  1971. end;
  1972. _TYPE:
  1973. begin
  1974. Not_supported_for_inline(token);
  1975. type_dec;
  1976. end;
  1977. _VAR:
  1978. var_dec;
  1979. _CONSTRUCTOR,_DESTRUCTOR,
  1980. _FUNCTION,_PROCEDURE,_OPERATOR,_CLASS:
  1981. begin
  1982. Not_supported_for_inline(token);
  1983. read_proc;
  1984. end;
  1985. _EXPORTS:
  1986. begin
  1987. Not_supported_for_inline(token);
  1988. { here we should be at lexlevel 1, no ? PM }
  1989. if (lexlevel<>main_program_level) or
  1990. (not islibrary and not DLLsource) then
  1991. begin
  1992. Message(parser_e_syntax_error);
  1993. consume_all_until(SEMICOLON);
  1994. end
  1995. else if islibrary then
  1996. read_exports;
  1997. end
  1998. else break;
  1999. end;
  2000. until false;
  2001. end;
  2002. procedure read_interface_declarations;
  2003. begin
  2004. {Since the body is now parsed at lexlevel 1, and the declarations
  2005. must be parsed at the same lexlevel we increase the lexlevel.}
  2006. inc(lexlevel);
  2007. repeat
  2008. case token of
  2009. _CONST : const_dec;
  2010. _TYPE : type_dec;
  2011. _VAR : var_dec;
  2012. _FUNCTION,
  2013. _PROCEDURE,
  2014. _OPERATOR : read_proc;
  2015. else
  2016. break;
  2017. end;
  2018. until false;
  2019. dec(lexlevel);
  2020. end;
  2021. end.
  2022. {
  2023. $Log$
  2024. Revision 1.93 1999-01-15 13:08:23 peter
  2025. * error if upper<lower in array decl
  2026. Revision 1.92 1999/01/14 21:49:58 peter
  2027. * fixed forwardpointer problem with multiple forwards for the same
  2028. typesym. It now uses a linkedlist instead of a single pointer
  2029. Revision 1.91 1998/12/30 22:15:46 peter
  2030. + farpointer type
  2031. * absolutesym now also stores if its far
  2032. Revision 1.90 1998/12/15 17:16:00 peter
  2033. * fixed const s : ^string
  2034. * first things for const pchar : @string[1]
  2035. Revision 1.89 1998/12/11 00:03:30 peter
  2036. + globtype,tokens,version unit splitted from globals
  2037. Revision 1.88 1998/11/30 09:43:20 pierre
  2038. * some range check bugs fixed (still not working !)
  2039. + added DLL writing support for win32 (also accepts variables)
  2040. + TempAnsi for code that could be used for Temporary ansi strings
  2041. handling
  2042. Revision 1.87 1998/11/29 12:42:24 peter
  2043. * check for constants with array decl
  2044. Revision 1.86 1998/11/28 16:20:52 peter
  2045. + support for dll variables
  2046. Revision 1.85 1998/11/27 14:34:43 peter
  2047. * give error when string[0] decl is found
  2048. Revision 1.84 1998/11/17 10:40:15 peter
  2049. * H+ fixes
  2050. Revision 1.83 1998/11/16 11:28:59 pierre
  2051. * stackcheck removed for i386_win32
  2052. * exportlist does not crash at least !!
  2053. (was need for tests dir !)z
  2054. Revision 1.82 1998/11/16 10:18:07 peter
  2055. * fixes for ansistrings
  2056. Revision 1.81 1998/11/13 15:40:22 pierre
  2057. + added -Se in Makefile cvstest target
  2058. + lexlevel cleanup
  2059. normal_function_level main_program_level and unit_init_level defined
  2060. * tins_cache grown to A_EMMS (gave range check error in asm readers)
  2061. (test added in code !)
  2062. * -Un option was wrong
  2063. * _FAIL and _SELF only keyword inside
  2064. constructors and methods respectively
  2065. Revision 1.80 1998/11/13 10:18:09 peter
  2066. + nil constants
  2067. Revision 1.79 1998/11/05 12:02:51 peter
  2068. * released useansistring
  2069. * removed -Sv, its now available in fpc modes
  2070. Revision 1.78 1998/10/27 13:45:33 pierre
  2071. * classes get a vmt allways
  2072. * better error info (tried to remove
  2073. several error strings introduced by the tpexcept handling)
  2074. Revision 1.77 1998/10/26 22:58:20 florian
  2075. * new introduded problem with classes fix, the parent class wasn't set
  2076. correct, if the class was defined forward before
  2077. Revision 1.76 1998/10/25 23:31:18 peter
  2078. * procvar parsing updated just like psub.pas routine
  2079. Revision 1.75 1998/10/21 08:39:59 florian
  2080. + ansistring operator +
  2081. + $h and string[n] for n>255 added
  2082. * small problem with TP fixed
  2083. Revision 1.74 1998/10/20 13:09:13 peter
  2084. * fixed object(unknown) crash
  2085. Revision 1.73 1998/10/19 08:54:56 pierre
  2086. * wrong stabs info corrected once again !!
  2087. + variable vmt offset with vmt field only if required
  2088. implemented now !!!
  2089. Revision 1.72 1998/10/16 13:12:51 pierre
  2090. * added vmt_offsets in destructors code also !!!
  2091. * vmt_offset code for m68k
  2092. Revision 1.71 1998/10/15 15:13:25 pierre
  2093. + added oo_hasconstructor and oo_hasdestructor
  2094. for objects options
  2095. Revision 1.70 1998/10/13 13:10:22 peter
  2096. * new style for m68k/i386 infos and enums
  2097. Revision 1.69 1998/10/09 12:07:49 pierre
  2098. * typo error for propertyparas dispose corrected
  2099. Revision 1.68 1998/10/09 11:47:54 pierre
  2100. * still more memory leaks fixes !!
  2101. Revision 1.67 1998/10/08 13:48:46 peter
  2102. * fixed memory leaks for do nothing source
  2103. * fixed unit interdependency
  2104. Revision 1.66 1998/10/06 20:43:31 peter
  2105. * fixed set of bugs. like set of false..true set of #1..#255 and
  2106. set of #1..true which was allowed
  2107. Revision 1.65 1998/10/05 22:43:35 peter
  2108. * commited the wrong file :(
  2109. Revision 1.64 1998/10/05 21:33:24 peter
  2110. * fixed 161,165,166,167,168
  2111. Revision 1.63 1998/10/05 13:57:13 peter
  2112. * crash preventions
  2113. Revision 1.62 1998/10/02 17:06:02 peter
  2114. * better error message for unresolved forward types
  2115. Revision 1.61 1998/10/02 09:23:24 peter
  2116. * fixed error msg with type l=<var>
  2117. * block_type bt_const is now set in read_const_dec
  2118. Revision 1.60 1998/09/30 07:40:33 florian
  2119. * better error recovering
  2120. Revision 1.59 1998/09/26 17:45:33 peter
  2121. + idtoken and only one token table
  2122. Revision 1.58 1998/09/25 00:04:01 florian
  2123. * problems when calling class methods fixed
  2124. Revision 1.57 1998/09/24 23:49:09 peter
  2125. + aktmodeswitches
  2126. Revision 1.56 1998/09/23 15:39:09 pierre
  2127. * browser bugfixes
  2128. was adding a reference when looking for the symbol
  2129. if -bSYM_NAME was used
  2130. Revision 1.55 1998/09/21 13:24:44 daniel
  2131. * Memory leak fixed.
  2132. Revision 1.54 1998/09/17 13:41:16 pierre
  2133. sizeof(TPOINT) problem
  2134. Revision 1.53.2.1 1998/09/17 13:12:09 pierre
  2135. * virtual destructor did not set oo_hasvirtual
  2136. (detected with the sizeof(TPoint) problem
  2137. * genloadcallnode was missing
  2138. Revision 1.53 1998/09/09 11:50:52 pierre
  2139. * forward def are not put in record or objects
  2140. + added check for forwards also in record and objects
  2141. * dummy parasymtable for unit initialization removed from
  2142. symtable stack
  2143. Revision 1.52 1998/09/07 23:10:22 florian
  2144. * a lot of stuff fixed regarding rtti and publishing of properties,
  2145. basics should now work
  2146. Revision 1.51 1998/09/07 19:33:22 florian
  2147. + some stuff for property rtti added:
  2148. - NameIndex of the TPropInfo record is now written correctly
  2149. - the DEFAULT/NODEFAULT keyword is supported now
  2150. - the default value and the storedsym/def are now written to
  2151. the PPU fiel
  2152. Revision 1.50 1998/09/07 18:46:08 peter
  2153. * update smartlinking, uses getdatalabel
  2154. * renamed ptree.value vars to value_str,value_real,value_set
  2155. Revision 1.49 1998/09/07 17:37:00 florian
  2156. * first fixes for published properties
  2157. Revision 1.48 1998/09/04 08:42:02 peter
  2158. * updated some error messages
  2159. Revision 1.47 1998/09/03 16:03:18 florian
  2160. + rtti generation
  2161. * init table generation changed
  2162. Revision 1.46 1998/09/01 17:39:48 peter
  2163. + internal constant functions
  2164. Revision 1.45 1998/08/31 12:20:28 peter
  2165. * fixed array_dec when unknown type was used
  2166. Revision 1.44 1998/08/28 10:57:01 peter
  2167. * removed warnings
  2168. Revision 1.43 1998/08/25 13:09:25 pierre
  2169. * corrected mangling sheme :
  2170. cvar add Cprefix to the mixed case name whereas
  2171. export or public use direct name
  2172. Revision 1.42 1998/08/25 12:42:41 pierre
  2173. * CDECL changed to CVAR for variables
  2174. specifications are read in structures also
  2175. + started adding GPC compatibility mode ( option -Sp)
  2176. * names changed to lowercase
  2177. Revision 1.41 1998/08/23 21:04:36 florian
  2178. + rtti generation for classes added
  2179. + new/dispose do now also a call to INITIALIZE/FINALIZE, if necessaray
  2180. Revision 1.40 1998/08/21 15:48:58 pierre
  2181. * more cdecl chagnes
  2182. - better line info
  2183. - changes the definition options of a procvar
  2184. if it is a unnamed type
  2185. Revision 1.39 1998/08/19 00:42:40 peter
  2186. + subrange types for enums
  2187. + checking for bounds type with ranges
  2188. Revision 1.38 1998/08/12 19:20:39 peter
  2189. + public is the same as export for c_vars
  2190. * a exported/public c_var incs now the refcount
  2191. Revision 1.37 1998/08/11 15:31:38 peter
  2192. * write extended to ppu file
  2193. * new version 0.99.7
  2194. Revision 1.36 1998/08/10 14:50:09 peter
  2195. + localswitches, moduleswitches, globalswitches splitting
  2196. Revision 1.35 1998/07/26 21:59:00 florian
  2197. + better support for switch $H
  2198. + index access to ansi strings added
  2199. + assigment of data (records/arrays) containing ansi strings
  2200. Revision 1.34 1998/07/20 22:17:15 florian
  2201. * hex constants in numeric char (#$54#$43 ...) are now allowed
  2202. * there was a bug in record_var_dec which prevents the used
  2203. of nested variant records (for example drivers.tevent of tv)
  2204. Revision 1.33 1998/07/18 17:11:11 florian
  2205. + ansi string constants fixed
  2206. + switch $H partial implemented
  2207. Revision 1.32 1998/07/14 21:46:50 peter
  2208. * updated messages file
  2209. Revision 1.31 1998/07/14 14:46:53 peter
  2210. * released NEWINPUT
  2211. Revision 1.30 1998/07/10 00:00:00 peter
  2212. * fixed ttypesym bug finally
  2213. * fileinfo in the symtable and better using for unused vars
  2214. Revision 1.29 1998/06/25 14:04:21 peter
  2215. + internal inc/dec
  2216. Revision 1.28 1998/06/24 12:26:45 peter
  2217. * stricter var parsing like tp7 and some optimizes with directive
  2218. parsing
  2219. Revision 1.27 1998/06/12 16:15:34 pierre
  2220. * external name 'C_var';
  2221. export name 'intern_C_var';
  2222. cdecl;
  2223. cdecl;external;
  2224. are now supported only with -Sv switch
  2225. Revision 1.25 1998/06/09 16:01:45 pierre
  2226. + added procedure directive parsing for procvars
  2227. (accepted are popstack cdecl and pascal)
  2228. + added C vars with the following syntax
  2229. var C calias 'true_c_name';(can be followed by external)
  2230. reason is that you must add the Cprefix
  2231. which is target dependent
  2232. Revision 1.24 1998/06/05 14:37:32 pierre
  2233. * fixes for inline for operators
  2234. * inline procedure more correctly restricted
  2235. Revision 1.23 1998/06/04 23:51:50 peter
  2236. * m68k compiles
  2237. + .def file creation moved to gendef.pas so it could also be used
  2238. for win32
  2239. Revision 1.22 1998/06/03 22:48:59 peter
  2240. + wordbool,longbool
  2241. * rename bis,von -> high,low
  2242. * moved some systemunit loading/creating to psystem.pas
  2243. Revision 1.21 1998/06/03 22:14:19 florian
  2244. * problem with sizes of classes fixed (if the anchestor was declared
  2245. forward, the compiler doesn't update the child classes size)
  2246. Revision 1.20 1998/05/28 14:35:54 peter
  2247. * nicer error message when no id is used after var
  2248. Revision 1.19 1998/05/23 01:21:19 peter
  2249. + aktasmmode, aktoptprocessor, aktoutputformat
  2250. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  2251. + $LIBNAME to set the library name where the unit will be put in
  2252. * splitted cgi386 a bit (codeseg to large for bp7)
  2253. * nasm, tasm works again. nasm moved to ag386nsm.pas
  2254. Revision 1.18 1998/05/20 09:42:35 pierre
  2255. + UseTokenInfo now default
  2256. * unit in interface uses and implementation uses gives error now
  2257. * only one error for unknown symbol (uses lastsymknown boolean)
  2258. the problem came from the label code !
  2259. + first inlined procedures and function work
  2260. (warning there might be allowed cases were the result is still wrong !!)
  2261. * UseBrower updated gives a global list of all position of all used symbols
  2262. with switch -gb
  2263. Revision 1.17 1998/05/11 13:07:55 peter
  2264. + $ifdef NEWPPU for the new ppuformat
  2265. + $define GDB not longer required
  2266. * removed all warnings and stripped some log comments
  2267. * no findfirst/findnext anymore to remove smartlink *.o files
  2268. Revision 1.16 1998/05/05 12:05:42 florian
  2269. * problems with properties fixed
  2270. * crash fixed: i:=l when i and l are undefined, was a problem with
  2271. implementation of private/protected
  2272. Revision 1.15 1998/05/01 09:01:23 florian
  2273. + correct semantics of private and protected
  2274. * small fix in variable scope:
  2275. a id can be used in a parameter list of a method, even it is used in
  2276. an anchestor class as field id
  2277. Revision 1.14 1998/05/01 07:43:56 florian
  2278. + basics for rtti implemented
  2279. + switch $m (generate rtti for published sections)
  2280. Revision 1.13 1998/04/30 15:59:41 pierre
  2281. * GDB works again better :
  2282. correct type info in one pass
  2283. + UseTokenInfo for better source position
  2284. * fixed one remaining bug in scanner for line counts
  2285. * several little fixes
  2286. Revision 1.12 1998/04/29 10:33:57 pierre
  2287. + added some code for ansistring (not complete nor working yet)
  2288. * corrected operator overloading
  2289. * corrected nasm output
  2290. + started inline procedures
  2291. + added starstarn : use ** for exponentiation (^ gave problems)
  2292. + started UseTokenInfo cond to get accurate positions
  2293. Revision 1.11 1998/04/28 11:45:52 florian
  2294. * make it compilable with TP
  2295. + small COM problems solved to compile classes.pp
  2296. Revision 1.10 1998/04/27 23:10:28 peter
  2297. + new scanner
  2298. * $makelib -> if smartlink
  2299. * small filename fixes pmodule.setfilename
  2300. * moved import from files.pas -> import.pas
  2301. Revision 1.9 1998/04/10 21:36:56 florian
  2302. + some stuff to support method pointers (procedure of object) added
  2303. (declaration, parameter handling)
  2304. Revision 1.8 1998/04/10 15:39:48 florian
  2305. * more fixes to get classes.pas compiled
  2306. Revision 1.7 1998/04/09 23:02:15 florian
  2307. * small problems solved to get remake3 work
  2308. Revision 1.6 1998/04/09 22:16:35 florian
  2309. * problem with previous REGALLOC solved
  2310. * improved property support
  2311. Revision 1.5 1998/04/08 14:59:20 florian
  2312. * problem with new expr_type solved
  2313. Revision 1.4 1998/04/08 10:26:09 florian
  2314. * correct error handling of virtual constructors
  2315. * problem with new type declaration handling fixed
  2316. Revision 1.3 1998/04/07 22:45:05 florian
  2317. * bug0092, bug0115 and bug0121 fixed
  2318. + packed object/class/array
  2319. Revision 1.2 1998/04/05 13:58:35 peter
  2320. * fixed the -Ss bug
  2321. + warning for Virtual constructors
  2322. * helppages updated with -TGO32V1
  2323. }