symconst.pas 17 KB

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