symconst.pas 19 KB

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