symconst.pas 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl, Pierre Muller
  4. Symbol table constants
  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 symconst;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. globtype;
  23. const
  24. def_alignment = 4;
  25. { if you change one of the following contants, }
  26. { you have also to change the typinfo unit}
  27. { and the rtl/i386,template/rttip.inc files }
  28. tkUnknown = 0;
  29. tkInteger = 1;
  30. tkChar = 2;
  31. tkEnumeration = 3;
  32. tkFloat = 4;
  33. tkSet = 5;
  34. tkMethod = 6;
  35. tkSString = 7;
  36. tkString = tkSString;
  37. tkLString = 8;
  38. {$ifdef ansistring_bits}
  39. tkA32String = 9;
  40. {$else}
  41. tkAString = 9;
  42. {$endif}
  43. tkWString = 10;
  44. tkVariant = 11;
  45. tkArray = 12;
  46. tkRecord = 13;
  47. tkInterface= 14;
  48. tkClass = 15;
  49. tkObject = 16;
  50. tkWChar = 17;
  51. tkBool = 18;
  52. tkInt64 = 19;
  53. tkQWord = 20;
  54. tkDynArray = 21;
  55. tkInterfaceCorba = 22;
  56. {$ifdef ansistring_bits}
  57. tkA16string = 23;
  58. tkA64string = 24;
  59. {$endif}
  60. otSByte = 0;
  61. otUByte = 1;
  62. otSWord = 2;
  63. otUWord = 3;
  64. otSLong = 4;
  65. otULong = 5;
  66. ftSingle = 0;
  67. ftDouble = 1;
  68. ftExtended = 2;
  69. ftComp = 3;
  70. ftCurr = 4;
  71. ftFloat128 = 5;
  72. mkProcedure= 0;
  73. mkFunction = 1;
  74. mkConstructor = 2;
  75. mkDestructor = 3;
  76. mkClassProcedure= 4;
  77. mkClassFunction = 5;
  78. pfvar = 1;
  79. pfConst = 2;
  80. pfArray = 4;
  81. pfAddress = 8;
  82. pfReference= 16;
  83. pfOut = 32;
  84. unknown_level = 0;
  85. main_program_level = 1;
  86. normal_function_level = 2;
  87. type
  88. { Deref entry options }
  89. tdereftype = (deref_nil,
  90. deref_sym,
  91. deref_def,
  92. deref_aktrecord,
  93. deref_aktstatic,
  94. deref_aktglobal,
  95. deref_aktlocal,
  96. deref_aktpara,
  97. deref_unit,
  98. deref_record,
  99. deref_local,
  100. deref_para,
  101. deref_parent_object
  102. );
  103. { symbol options }
  104. tsymoption=(sp_none,
  105. sp_public,
  106. sp_private,
  107. sp_published,
  108. sp_protected,
  109. sp_static,
  110. sp_hint_deprecated,
  111. sp_hint_platform,
  112. sp_hint_library,
  113. sp_hint_unimplemented,
  114. sp_has_overloaded,
  115. sp_internal { internal symbol, not reported as unused }
  116. );
  117. tsymoptions=set of tsymoption;
  118. { flags for a definition }
  119. tdefoption=(df_none,
  120. { init data has been generated }
  121. df_has_inittable,
  122. { rtti data has been generated }
  123. df_has_rttitable,
  124. { type is unique, i.e. declared with type = type <tdef>; }
  125. df_unique
  126. );
  127. tdefoptions=set of tdefoption;
  128. { tsymlist entry types }
  129. tsltype = (sl_none,
  130. sl_load,
  131. sl_call,
  132. sl_subscript,
  133. sl_vec,
  134. sl_typeconv
  135. );
  136. { base types for orddef }
  137. tbasetype = (
  138. uvoid,
  139. u8bit,u16bit,u32bit,u64bit,
  140. s8bit,s16bit,s32bit,s64bit,
  141. bool8bit,bool16bit,bool32bit,
  142. uchar,uwidechar,scurrency
  143. );
  144. { float types }
  145. tfloattype = (
  146. s32real,s64real,s80real,
  147. s64comp,s64currency,s128real
  148. );
  149. { string types }
  150. tstringtype = (st_default,
  151. st_shortstring,
  152. st_longstring,
  153. {$ifndef ansistring_bits}
  154. st_ansistring,
  155. {$else}
  156. st_ansistring16,
  157. st_ansistring32,
  158. st_ansistring64,
  159. {$endif}
  160. st_widestring
  161. );
  162. { set types }
  163. tsettype = (
  164. normset,smallset,varset
  165. );
  166. tvarianttype = (
  167. vt_normalvariant,vt_olevariant
  168. );
  169. tcallercallee = (callerside,calleeside);
  170. { basic type for tprocdef and tprocvardef }
  171. tproctypeoption=(potype_none,
  172. potype_proginit, { Program initialization }
  173. potype_unitinit, { unit initialization }
  174. potype_unitfinalize, { unit finalization }
  175. potype_constructor, { Procedure is a constructor }
  176. potype_destructor, { Procedure is a destructor }
  177. potype_operator { Procedure defines an operator }
  178. );
  179. tproctypeoptions=set of tproctypeoption;
  180. { other options for tprocdef and tprocvardef }
  181. tprocoption=(po_none,
  182. po_classmethod, { class method }
  183. po_virtualmethod, { Procedure is a virtual method }
  184. po_abstractmethod, { Procedure is an abstract method }
  185. po_staticmethod, { static method }
  186. po_overridingmethod, { method with override directive }
  187. po_methodpointer, { method pointer, only in procvardef, also used for 'with object do' }
  188. po_interrupt, { Procedure is an interrupt handler }
  189. po_iocheck, { IO checking should be done after a call to the procedure }
  190. po_assembler, { Procedure is written in assembler }
  191. po_msgstr, { method for string message handling }
  192. po_msgint, { method for int message handling }
  193. po_exports, { Procedure has export directive (needed for OS/2) }
  194. po_external, { Procedure is external (in other object or lib)}
  195. po_saveregisters, { save all registers }
  196. po_overload, { procedure is declared with overload directive }
  197. po_varargs, { printf like arguments }
  198. po_internconst, { procedure has constant evaluator intern }
  199. { flag that only the address of a method is returned and not a full methodpointer }
  200. po_addressonly,
  201. { procedure is exported }
  202. po_public,
  203. { calling convention is specified explicitly }
  204. po_hascallingconvention,
  205. { reintroduce flag }
  206. po_reintroduce,
  207. { location of parameters is given explicitly as it is necessary for some syscall
  208. conventions like that one of MorphOS }
  209. po_explicitparaloc
  210. );
  211. tprocoptions=set of tprocoption;
  212. { options for objects and classes }
  213. tobjectdeftype = (odt_none,
  214. odt_class,
  215. odt_object,
  216. odt_interfacecom,
  217. odt_interfacecorba,
  218. odt_cppclass,
  219. odt_dispinterface
  220. );
  221. { options for objects and classes }
  222. tobjectoption=(oo_none,
  223. oo_is_forward, { the class is only a forward declared yet }
  224. oo_has_virtual, { the object/class has virtual methods }
  225. oo_has_private,
  226. oo_has_protected,
  227. oo_has_constructor, { the object/class has a constructor }
  228. oo_has_destructor, { the object/class has a destructor }
  229. oo_has_vmt, { the object/class has a vmt }
  230. oo_has_msgstr,
  231. oo_has_msgint,
  232. oo_can_have_published { the class has rtti, i.e. you can publish properties }
  233. );
  234. tobjectoptions=set of tobjectoption;
  235. { options for properties }
  236. tpropertyoption=(ppo_none,
  237. ppo_indexed,
  238. ppo_defaultproperty,
  239. ppo_stored,
  240. ppo_hasparameters,
  241. ppo_is_override
  242. );
  243. tpropertyoptions=set of tpropertyoption;
  244. { options for variables }
  245. tvaroption=(vo_none,
  246. vo_regable,
  247. vo_is_C_var,
  248. vo_is_external,
  249. vo_is_dll_var,
  250. vo_is_thread_var,
  251. vo_fpuregable,
  252. vo_has_local_copy,
  253. vo_is_const, { variable is declared as const (parameter) and can't be written to }
  254. vo_is_exported,
  255. vo_is_high_value,
  256. vo_is_funcret,
  257. vo_is_self,
  258. vo_is_vmt,
  259. vo_is_result, { special result variable }
  260. vo_is_reg_para, { register parameter, no space allocation in parast, but in localst }
  261. vo_is_parentfp
  262. );
  263. tvaroptions=set of tvaroption;
  264. { types of the symtables }
  265. tsymtabletype = (abstractsymtable,
  266. globalsymtable,staticsymtable,
  267. objectsymtable,recordsymtable,
  268. localsymtable,parasymtable,
  269. withsymtable,stt_exceptsymtable
  270. );
  271. { definition contains the informations about a type }
  272. tdeftype = (abstractdef,arraydef,recorddef,pointerdef,orddef,
  273. stringdef,enumdef,procdef,objectdef,errordef,
  274. filedef,formaldef,setdef,procvardef,floatdef,
  275. classrefdef,forwarddef,variantdef);
  276. { possible types for symtable entries }
  277. tsymtyp = (abstractsym,varsym,typesym,procsym,unitsym,
  278. constsym,enumsym,typedconstsym,errorsym,syssym,
  279. labelsym,absolutesym,propertysym,macrosym,rttisym);
  280. { State of the variable, if it's declared, assigned or used }
  281. tvarstate=(vs_none,
  282. vs_declared,vs_assigned,vs_used
  283. );
  284. tvarspez = (vs_value,vs_const,vs_var,vs_out);
  285. absolutetyp = (tovar,toasm,toaddr);
  286. tconsttyp = (constnone,
  287. constord,conststring,constreal,
  288. constset,constpointer,constnil,
  289. constresourcestring,constwstring,constguid
  290. );
  291. { RTTI information to store }
  292. trttitype = (
  293. fullrtti,initrtti
  294. );
  295. { The order is from low priority to high priority,
  296. Note: the operators > and < are used on this list }
  297. tequaltype = (
  298. te_incompatible,
  299. te_convert_operator,
  300. te_convert_l3, { compatible conversion with possible loss of data }
  301. te_convert_l2, { compatible less prefered conversion }
  302. te_convert_l1, { compatible conversion }
  303. te_equal, { the definitions are equal }
  304. te_exact
  305. );
  306. tprocinfoflag=(
  307. {# procedure uses asm }
  308. pi_uses_asm,
  309. {# procedure does a call }
  310. pi_do_call,
  311. {# procedure has a try statement = no register optimization }
  312. pi_uses_exceptions,
  313. {# procedure is declared as @var(assembler), don't optimize}
  314. pi_is_assembler,
  315. {# procedure contains data which needs to be finalized }
  316. pi_needs_implicit_finally,
  317. {# procedure uses fpu}
  318. pi_uses_fpu,
  319. pi_needs_got
  320. );
  321. tprocinfoflags=set of tprocinfoflag;
  322. {$ifdef GDB}
  323. type
  324. tdefstabstatus = (
  325. stab_state_unused,
  326. stab_state_used,
  327. stab_state_writing,
  328. stab_state_written
  329. );
  330. const
  331. tagtypes : Set of tdeftype =
  332. [recorddef,enumdef,
  333. {$IfNDef GDBKnowsStrings}
  334. stringdef,
  335. {$EndIf not GDBKnowsStrings}
  336. {$IfNDef GDBKnowsFiles}
  337. filedef,
  338. {$EndIf not GDBKnowsFiles}
  339. objectdef];
  340. {$endif GDB}
  341. const
  342. savestdregs_pocalls = [
  343. pocall_cdecl,pocall_cppdecl,pocall_syscall,
  344. pocall_stdcall,pocall_safecall,pocall_compilerproc,
  345. pocall_register,pocall_softfloat
  346. ];
  347. clearstack_pocalls = [
  348. pocall_cdecl,pocall_cppdecl,pocall_syscall
  349. ];
  350. pushleftright_pocalls : tproccalloptions = [pocall_register,pocall_pascal];
  351. SymTypeName : array[tsymtyp] of string[12] = (
  352. 'abstractsym','variable','type','proc','unit',
  353. 'const','enum','typed const','errorsym','system sym',
  354. 'label','absolute','property','macrosym','rttisym'
  355. );
  356. DefTypeName : array[tdeftype] of string[12] = (
  357. 'abstractdef','arraydef','recorddef','pointerdef','orddef',
  358. 'stringdef','enumdef','procdef','objectdef','errordef',
  359. 'filedef','formaldef','setdef','procvardef','floatdef',
  360. 'classrefdef','forwarddef','variantdef'
  361. );
  362. EqualTypeName : array[tequaltype] of string[16] = (
  363. 'incompatible','convert_operator','convert_l3','convert_l2',
  364. 'convert_l1','equal','exact'
  365. );
  366. implementation
  367. initialization
  368. if pocall_default in [pocall_register,pocall_internproc] then
  369. include(pushleftright_pocalls,pocall_compilerproc);
  370. end.
  371. {
  372. $Log$
  373. Revision 1.81 2004-04-29 19:56:37 daniel
  374. * Prepare compiler infrastructure for multiple ansistring types
  375. Revision 1.80 2004/04/28 15:19:03 florian
  376. + syscall directive support for MorphOS added
  377. Revision 1.79 2004/04/18 15:22:24 florian
  378. + location support for arguments, currently PowerPC/MorphOS only
  379. Revision 1.78 2004/03/23 22:34:49 peter
  380. * constants ordinals now always have a type assigned
  381. * integer constants have the smallest type, unsigned prefered over
  382. signed
  383. Revision 1.77 2004/03/08 22:07:47 peter
  384. * stabs updates to write stabs for def for all implictly used
  385. units
  386. Revision 1.76 2004/02/27 10:21:05 florian
  387. * top_symbol killed
  388. + refaddr to treference added
  389. + refsymbol to treference added
  390. * top_local stuff moved to an extra record to save memory
  391. + aint introduced
  392. * tppufile.get/putint64/aint implemented
  393. Revision 1.75 2004/02/20 21:54:47 peter
  394. * use sp_internal flag to silence unused internal variable
  395. Revision 1.74 2004/01/21 14:22:00 florian
  396. + reintroduce implemented
  397. Revision 1.73 2003/12/19 22:08:44 daniel
  398. * Some work to restore the MMX capabilities
  399. Revision 1.72 2003/12/16 21:29:24 florian
  400. + inlined procedures inherit procinfo flags
  401. Revision 1.71 2003/11/23 17:05:16 peter
  402. * register calling is left-right
  403. * parameter ordering
  404. * left-right calling inserts result parameter last
  405. Revision 1.70 2003/11/07 15:58:32 florian
  406. * Florian's culmutative nr. 1; contains:
  407. - invalid calling conventions for a certain cpu are rejected
  408. - arm softfloat calling conventions
  409. - -Sp for cpu dependend code generation
  410. - several arm fixes
  411. - remaining code for value open array paras on heap
  412. Revision 1.69 2003/10/28 15:36:01 peter
  413. * absolute to object field supported, fixes tb0458
  414. Revision 1.68 2003/10/08 19:19:45 peter
  415. * set_varstate cleanup
  416. Revision 1.67 2003/10/07 15:17:07 peter
  417. * inline supported again, LOC_REFERENCEs are used to pass the
  418. parameters
  419. * inlineparasymtable,inlinelocalsymtable removed
  420. * exitlabel inserting fixed
  421. Revision 1.66 2003/10/06 22:23:41 florian
  422. + added basic olevariant support
  423. Revision 1.65 2003/09/28 17:55:04 peter
  424. * parent framepointer changed to hidden parameter
  425. * tloadparentfpnode added
  426. Revision 1.64 2003/09/23 17:56:06 peter
  427. * locals and paras are allocated in the code generation
  428. * tvarsym.localloc contains the location of para/local when
  429. generating code for the current procedure
  430. Revision 1.63 2003/09/09 21:03:17 peter
  431. * basics for x86 register calling
  432. Revision 1.62 2003/09/09 15:54:10 peter
  433. * calling convention fix
  434. Revision 1.61 2003/09/07 22:09:35 peter
  435. * preparations for different default calling conventions
  436. * various RA fixes
  437. Revision 1.60 2003/08/11 21:18:20 peter
  438. * start of sparc support for newra
  439. Revision 1.59 2003/08/10 17:25:23 peter
  440. * fixed some reported bugs
  441. Revision 1.58 2003/06/25 18:31:23 peter
  442. * sym,def resolving partly rewritten to support also parent objects
  443. not directly available through the uses clause
  444. Revision 1.57 2003/06/07 20:26:32 peter
  445. * re-resolving added instead of reloading from ppu
  446. * tderef object added to store deref info for resolving
  447. Revision 1.56 2003/05/22 21:31:35 peter
  448. * defer codegeneration for nested procedures
  449. Revision 1.55 2003/05/15 21:10:32 peter
  450. * remove po_containsself
  451. Revision 1.54 2003/05/09 17:47:03 peter
  452. * self moved to hidden parameter
  453. * removed hdisposen,hnewn,selfn
  454. Revision 1.53 2003/05/05 14:53:16 peter
  455. * vs_hidden replaced by is_hidden boolean
  456. Revision 1.52 2003/04/27 11:21:34 peter
  457. * aktprocdef renamed to current_procdef
  458. * procinfo renamed to current_procinfo
  459. * procinfo will now be stored in current_module so it can be
  460. cleaned up properly
  461. * gen_main_procsym changed to create_main_proc and release_main_proc
  462. to also generate a tprocinfo structure
  463. * fixed unit implicit initfinal
  464. Revision 1.51 2003/04/27 07:29:51 peter
  465. * current_procdef cleanup, current_procdef is now always nil when parsing
  466. a new procdef declaration
  467. * aktprocsym removed
  468. * lexlevel removed, use symtable.symtablelevel instead
  469. * implicit init/final code uses the normal genentry/genexit
  470. * funcret state checking updated for new funcret handling
  471. Revision 1.50 2003/04/26 00:33:07 peter
  472. * vo_is_result flag added for the special RESULT symbol
  473. Revision 1.49 2003/04/25 20:59:35 peter
  474. * removed funcretn,funcretsym, function result is now in varsym
  475. and aliases for result and function name are added using absolutesym
  476. * vs_hidden parameter for funcret passed in parameter
  477. * vs_hidden fixes
  478. * writenode changed to printnode and released from extdebug
  479. * -vp option added to generate a tree.log with the nodetree
  480. * nicer printnode for statements, callnode
  481. Revision 1.48 2003/04/23 20:16:04 peter
  482. + added currency support based on int64
  483. + is_64bit for use in cg units instead of is_64bitint
  484. * removed cgmessage from n386add, replace with internalerrors
  485. Revision 1.47 2003/04/23 11:37:33 peter
  486. * po_comp for proc to procvar fixed
  487. Revision 1.46 2003/01/16 22:13:52 peter
  488. * convert_l3 convertlevel added. This level is used for conversions
  489. where information can be lost like converting widestring->ansistring
  490. or dword->byte
  491. Revision 1.45 2003/01/09 21:52:37 peter
  492. * merged some verbosity options.
  493. * V_LineInfo is a verbosity flag to include line info
  494. Revision 1.44 2003/01/06 21:16:52 peter
  495. * po_addressonly added to retrieve the address of a methodpointer
  496. only, this is used for @tclass.method which has no self pointer
  497. Revision 1.43 2003/01/05 15:54:15 florian
  498. + added proper support of type = type <type>; for simple types
  499. Revision 1.42 2003/01/05 13:36:53 florian
  500. * x86-64 compiles
  501. + very basic support for float128 type (x86-64 only)
  502. Revision 1.41 2003/01/01 22:51:03 peter
  503. * high value insertion changed so it works also when 2 parameters
  504. are passed
  505. Revision 1.40 2002/12/29 14:57:50 peter
  506. * unit loading changed to first register units and load them
  507. afterwards. This is needed to support uses xxx in yyy correctly
  508. * unit dependency check fixed
  509. Revision 1.39 2002/12/15 11:26:02 peter
  510. * ignore vs_hidden parameters when choosing overloaded proc
  511. Revision 1.38 2002/12/05 14:44:38 florian
  512. + oo_dispinterface added
  513. Revision 1.37 2002/11/29 22:31:20 carl
  514. + unimplemented hint directive added
  515. * hint directive parsing implemented
  516. * warning on these directives
  517. Revision 1.36 2002/10/20 15:34:16 peter
  518. * removed df_unique flag. It breaks code. For a good type=type <id>
  519. a def copy is required
  520. Revision 1.35 2002/10/06 12:25:05 florian
  521. + proper support of type <id> = type <another id>;
  522. Revision 1.34 2002/08/19 19:36:44 peter
  523. * More fixes for cross unit inlining, all tnodes are now implemented
  524. * Moved pocall_internconst to po_internconst because it is not a
  525. calling type at all and it conflicted when inlining of these small
  526. functions was requested
  527. Revision 1.33 2002/07/01 16:23:54 peter
  528. * cg64 patch
  529. * basics for currency
  530. * asnode updates for class and interface (not finished)
  531. Revision 1.32 2002/05/18 13:34:18 peter
  532. * readded missing revisions
  533. Revision 1.31 2002/05/16 19:46:44 carl
  534. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  535. + try to fix temp allocation (still in ifdef)
  536. + generic constructor calls
  537. + start of tassembler / tmodulebase class cleanup
  538. Revision 1.30 2002/05/14 19:34:50 peter
  539. * removed old logs and updated copyright year
  540. Revision 1.29 2002/05/12 16:53:10 peter
  541. * moved entry and exitcode to ncgutil and cgobj
  542. * foreach gets extra argument for passing local data to the
  543. iterator function
  544. * -CR checks also class typecasts at runtime by changing them
  545. into as
  546. * fixed compiler to cycle with the -CR option
  547. * fixed stabs with elf writer, finally the global variables can
  548. be watched
  549. * removed a lot of routines from cga unit and replaced them by
  550. calls to cgobj
  551. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  552. u32bit then the other is typecasted also to u32bit without giving
  553. a rangecheck warning/error.
  554. * fixed pascal calling method with reversing also the high tree in
  555. the parast, detected by tcalcst3 test
  556. Revision 1.28 2002/01/06 12:08:15 peter
  557. * removed uauto from orddef, use new range_to_basetype generating
  558. the correct ordinal type for a range
  559. }