system.H 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. /*-
  2. * Copyright (c) 1998, 2002-2008 Kiyoshi Matsui <kmatsui@t3.rim.or.jp>
  3. * All rights reserved.
  4. *
  5. * Some parts of this code are derived from the public domain software
  6. * DECUS cpp (1984,1985) written by Martin Minow.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. /*
  30. * S Y S T E M . H
  31. * S y s t e m D e p e n d e n t
  32. * D e f i n i t i o n s f o r M C P P
  33. *
  34. * Definitions in this file may be edited to configure MCPP for particular
  35. * operating systems and compiler configurations.
  36. *
  37. * Note: MCPP assumes the system implement the Ascii character set.
  38. * If this is not the case, you will have to do some editing here and there.
  39. */
  40. #define SYSTEM_H
  41. #if HAVE_CONFIG_H
  42. #include "configed.H"
  43. #else
  44. #include "noconfig.H"
  45. #endif
  46. /* Some system has a wrong definition of UCHAR_MAX. See cpp-test.html#5.1.3 */
  47. #if UCHARMAX < -255
  48. /* The definition of UCHARMAX (possibly UCHAR_MAX too) is wrong. */
  49. /* Define it as a signed int value, not as an unsigned value. */
  50. #undef UCHARMAX
  51. #define UCHARMAX ((1 << CHAR_BIT) - 1)
  52. #endif
  53. /*
  54. * PART 1 and PART 2 are defined in the above header files.
  55. */
  56. /*
  57. * P A R T 1 Configurations for target-operating-system
  58. * and target-compiler.
  59. */
  60. /*
  61. * P A R T 2 Configurations for host-compiler.
  62. */
  63. /*
  64. * P A R T 3 Configurations for default settings, typedefs and
  65. * translation limits.
  66. */
  67. /*
  68. * The variable 'mcpp_mode' specifies the mode of preprocessing as one of
  69. * OLD_PREP, KR, STD, or POST_STD.
  70. * Those modes have many differences each other --
  71. * i.e. handling of translation phases; handling of some
  72. * preprocessing tokens; availability of some directives; way of
  73. * macro expansion;
  74. * -- as follows.
  75. *
  76. * KR Actual arguments of a macro are expanded (after substitution)
  77. * with rest of the replacement text and the subsequent source text.
  78. * ## in macro definition has no significance to cpp. The surrounding
  79. * tokens are macro-expanded separately. Also, # has no significance
  80. * to cpp. The following token is expanded.
  81. * Directly or intermediately recursive macro call causes an error.
  82. * <backslash><newline> sequence is deleted only in string literals
  83. * and in #define directive lines.
  84. * sizeof (type) can be used in #if line.
  85. * KR corresponds to the "K&R 1st."
  86. *
  87. * OLD_PREP In addition to the KR specifications, this mode has the
  88. * following characteristics (and some others).
  89. * Converts comment to 0 space instead of 1 space.
  90. * Expands the parameter like spelling in string literal as a macro.
  91. * Does not check unmatched pair of '"' or '\''.
  92. * OLD_PREP corresponts to "Reiser model" cpp.
  93. *
  94. * STD Standard conforming mode.
  95. * <backslash><newline> sequence is always deleted after trigraph
  96. * conversion and before tokenization.
  97. * Digraph sequences are recognized as tokens.
  98. * Actual arguments of a macro are expanded separately prior to
  99. * re-scanning of the replacement text.
  100. * The name in the replacement text once expanded is not re-expanded,
  101. * thus preventing recursive death.
  102. * ## in macro definition concatenates tokens. The tokens are not
  103. * expanded. The concatenated token is expanded by rescanning.
  104. * # in macro definition stringizes the following argument. The argument
  105. * is not expanded. \ is inserted before " and \ in or surrounding
  106. * the string literal or character constant.
  107. * An expanded macro is surrounded by spaces to prevent unintended
  108. * token merging.
  109. *
  110. * POST_STD This mode simplifies the behavior of STD mode as follows.
  111. * 1. Digraph sequences are converted in translation phase 1, as
  112. * alternate characters rather than as tokens.
  113. * 2. A space is inserted as a token separator between any tokens in
  114. * a source (except a macro name and the next '(' in macro
  115. * definition): thus simplifying tokenization, test of macro
  116. * redefinition and macro expansion, especially "stringization".
  117. * 3. Test of macro redefinition ignores difference of parameter names,
  118. * test of which has little utility and not a little overhead.
  119. * 4. #if expression forbids character constants, which have little
  120. * portability, little utility and not a little overhead.
  121. * 5. Rescanning of a macro expansion is limited in the replacement
  122. * text, rest of the source file is not scanned, thus making the
  123. * syntax of "function-like" macro call more similar to that of
  124. * function call.
  125. * 6. Argument of #include directive in <header.h> form is an obsolescent
  126. * feature.
  127. * 7. '$' or so are not treated specially in #define directive.
  128. * 8. Trigraphs, UCN (universal-character name) are not recognized.
  129. * 9. Multi-byte characters in an identifier are not recognized.
  130. *
  131. * The following specifications are available when mode is STD or POST_STD.
  132. * preprocessing number token, digraphs,
  133. * #pragma (#pragma MCPP put_defines, #pragma MCPP warning
  134. * , #pragma MCPP debug) directive,
  135. * #error directive,
  136. * #if defined operator, #elif directive,
  137. * predefined macros __FILE__, __LINE__, __DATE__, __TIME__
  138. * , __STDC__, __STDC_VERSION__, __STDC_HOSTED__,
  139. * wide character constant, wide character string literal,
  140. * _Pragma() operator, variable-arguments macro,
  141. * macro as an argument of #include, #line directives,
  142. * escape sequences \x[hex-digits], \a, \v,
  143. * '+' option (C++ preprocessing),
  144. * 'S<n>' option (re-defines __STDC__ as <n>, unpredefine some macros),
  145. * 'V<n>' option (re-defines __STDC_VERSION__ or __cplusplus as <n>),
  146. * 'h<n>' option (re-defines __STDC_HOSTED__ as <n>).
  147. * The following specifications are available only in STD mode.
  148. * Trigraphs and UCN,
  149. * Multi-byte characters in an identifier.
  150. * The following specifications are available only in KR and OLD_PREP modes.
  151. * #assert, #asm, #endasm, #put_defines, #debug and some other older
  152. * directives,
  153. * argument of #line directive other than decimal-digits.
  154. */
  155. /* The values of 'mcpp_mode'. */
  156. #define OLD_PREP 1 /* "Reiser" cpp mode */
  157. #define KR 2 /* K&R 1st mode */
  158. #define STD 3 /* Standard moce */
  159. #define POST_STD 9 /* Special mode of MCPP */
  160. /*
  161. * TRIGRAPHS_INIT Initial value for the -3 option. If TRUE -3
  162. * disables trigraphs, if FALSE -3 enables them.
  163. * DIGRAPHS_INIT Initial value for the -2 option. If TRUE -2
  164. * disables digraphs, if FALSE -2 enables them.
  165. * OK_UCN Enable recognition of Universal-Character-Name sequence
  166. * by -V199901L option.
  167. * OK_MBIDENT Enable multi-byte characters in identifier by -V199901L
  168. * option.
  169. * EXPAND_PRAGMA Enable macro expansion of #pragma line (even in modes
  170. * other than C99).
  171. * expr_t, uexpr_t Type of maximum integer:
  172. * long long (unsigned long long) or longer.
  173. * EXPR_MAX should be defined to the maximum value of uexpr_t.
  174. */
  175. #define TRIGRAPHS_INIT FALSE
  176. #define DIGRAPHS_INIT FALSE
  177. #ifndef EXPAND_PRAGMA
  178. #define EXPAND_PRAGMA FALSE
  179. #endif
  180. #define OK_UCN TRUE
  181. #define OK_MBIDENT FALSE
  182. #if HAVE_INTMAX_T
  183. #if HAVE_STDINT_H
  184. #include "stdint.h"
  185. #elif HAVE_INTTYPES_H
  186. #include "inttypes.h"
  187. #endif
  188. typedef intmax_t expr_t;
  189. typedef uintmax_t uexpr_t;
  190. #else
  191. #if HAVE_LONG_LONG
  192. #if (HOST_COMPILER == MSC && _MSC_VER < 1500) || HOST_COMPILER == BORLANDC
  193. typedef __int64 expr_t;
  194. typedef unsigned __int64 uexpr_t;
  195. #else
  196. typedef long long expr_t;
  197. typedef unsigned long long uexpr_t;
  198. #endif
  199. #else /* !HAVE_LONG_LONG */
  200. typedef unsigned long uexpr_t;
  201. typedef long expr_t;
  202. #endif /* HAVE_LONG_LONG */
  203. #endif /* HAVE_INTMAX_T */
  204. #if HAVE_INTMAX_T
  205. #define EXPR_MAX UINTMAX_MAX
  206. #elif HAVE_LONG_LONG
  207. #if (HOST_COMPILER == MSC && _MSC_VER < 1400) || HOST_COMPILER == BORLANDC
  208. #define EXPR_MAX 0xFFFFFFFFFFFFFFFFui64
  209. #else
  210. #define EXPR_MAX 0xFFFFFFFFFFFFFFFFULL
  211. #endif
  212. #else
  213. #define EXPR_MAX 4294967295UL
  214. #endif
  215. /*
  216. * Translation limits.
  217. * The following definitions are used to allocate memory for work buffers.
  218. *
  219. * NWORK Output buffer size. Set this size according to your compiler-
  220. * proper. Length of string literal should be less than NWORK
  221. * - 1.
  222. * Nevertheless, when COMPILER == GNUC || COMPILER == MSC, mcpp
  223. * uses NMACWORK as output buffer size because GNUC and Visual C
  224. * can accept very long line.
  225. * NBUFF Input buffer size after line concatenation by <backslash>
  226. * <newline>.
  227. * NMACWORK Internal work buffer size for macro definition and expansion.
  228. * IDMAX The longest identifier length.
  229. * NMACPARS The maximum number of #define parameters.
  230. * NOTE: Must be NMACPARS <= UCHARMAX.
  231. * NEXP The maximum nesting depth of #if expressions.
  232. * BLK_NEST The number of nested #if's permitted.
  233. * INCLUDE_NEST The maximum nesting depth of #include. This is needed to
  234. * prevent infinite recursive inclusion.
  235. * RESCAN_LIMIT The maximum rescan times of macro expansion in STD or POST_STD
  236. * modes.
  237. * PRESTD_RESCAN_LIMIT The maximum rescan times of macro expansion in KR or
  238. * OLD_PREP modes..
  239. *
  240. * NBUFF should not be smaller than NWORK.
  241. * NMACWORK should not be smaller than NWORK * 2.
  242. *
  243. * SBSIZE defines the number of hash-table slots for the macro symbol table.
  244. * It must be a power of 2.
  245. *
  246. * MKDEP_INIT The initial maximum number of filenames in a dependency line
  247. * of output of -M* option. The maximum number is dynamically
  248. * enlarged in execution.
  249. */
  250. #ifndef IDMAX
  251. #define IDMAX 0x400
  252. #endif
  253. #ifndef NMACPARS
  254. #define NMACPARS 0xFF
  255. #endif
  256. #ifndef NEXP
  257. #define NEXP 0x100
  258. #endif
  259. #ifndef BLK_NEST
  260. #define BLK_NEST 0x100
  261. #endif
  262. #ifndef INCLUDE_NEST
  263. #define INCLUDE_NEST 0x100
  264. #endif
  265. #ifndef RESCAN_LIMIT
  266. #define RESCAN_LIMIT 0x40
  267. #endif
  268. #ifndef PRESTD_RESCAN_LIMIT
  269. #define PRESTD_RESCAN_LIMIT 0x100
  270. #endif
  271. #ifndef NBUFF
  272. #define NBUFF 0x10000 /* Must be NWORK <= NBUFF */
  273. #endif
  274. #ifndef NWORK
  275. #define NWORK NBUFF /* 0x1000, 0x4000, 0x10000, .. */
  276. #endif
  277. #ifndef NMACWORK
  278. #define NMACWORK (NWORK * 4) /* Must be NWORK * 2 <= NMACWORK */
  279. #endif
  280. #ifndef SBSIZE
  281. #define SBSIZE 0x400
  282. #endif
  283. #ifndef MKDEP_INIT
  284. #define MKDEP_INIT 0x100
  285. #endif
  286. #if UCHARMAX < NMACPARS
  287. #error "NMACPARS should not be greater than UCHARMAX"
  288. #endif
  289. #if NBUFF < NWORK
  290. #error "NBUFF must be same or greater than NWORK"
  291. #endif
  292. #if NMACWORK < NWORK * 2
  293. #error "NMACWORK must be same or greater than NWORK * 2"
  294. #endif
  295. #define SBMASK (SBSIZE - 1)
  296. #if (SBSIZE ^ SBMASK) != ((SBSIZE * 2) - 1)
  297. #error "SBSIZE must be a power of 2 !"
  298. #endif
  299. /*
  300. * Translation limits required by the Standard.
  301. *
  302. * *90MIN limits specified by C90.
  303. * *99MIN limits specified by C99.
  304. * *_CPLUS_MIN limits recommended by C++ (ISO 1998/07 Standard).
  305. *
  306. * SLEN*MIN Characters in a logical source line
  307. * and characters in a string literal or wide string literal
  308. * (after concatenation).
  309. * IDLEN*MIN Significant initial characters in an internal identifier
  310. * or a macro name.
  311. * NMACPARS*MIN Parameters in one macro definition.
  312. * Arguments in one macro invocation.
  313. * EXP_NEST*MIN Nesting levels of parenthesized expressions in a full
  314. * expression.
  315. * BLK_NEST*MIN Nesting levels of conditional inclusion.
  316. * INCLUDE_NEST*MIN Nesting levels for #include files.
  317. * NMACRO*MIN Macro identifiers simultaneously defined in one translation
  318. * unit.
  319. */
  320. #define SLEN90MIN 0x1FD
  321. #define IDLEN90MIN 0x1F
  322. #define NMACPARS90MIN 0x1F
  323. #define EXP_NEST90MIN 0x20
  324. #define BLK_NEST90MIN 8
  325. #define INCLUDE_NEST90MIN 8
  326. #define NMACRO90MIN 0x400
  327. #define SLEN99MIN 0xFFF
  328. #define IDLEN99MIN 0x3F
  329. #define NMACPARS99MIN 0x7F
  330. #define EXP_NEST99MIN 0x3F
  331. #define BLK_NEST99MIN 0x3F
  332. #define INCLUDE_NEST99MIN 0xF
  333. #define NMACRO99MIN 0xFFF
  334. #define SLEN_CPLUS_MIN 0x10000
  335. #define IDLEN_CPLUS_MIN 0x400
  336. #define NMACPARS_CPLUS_MIN 0x100
  337. #define EXP_NEST_CPLUS_MIN 0x100
  338. #define BLK_NEST_CPLUS_MIN 0x100
  339. #define INCLUDE_NEST_CPLUS_MIN 0x100
  340. #define NMACRO_CPLUS_MIN 0x10000
  341. /* LINE99LIMIT means the line number limit of C99 */
  342. #define LINE99LIMIT 0x7FFFFFFF
  343. /*
  344. * STDC This macro is used for the predefined __STDC__.
  345. * STDC_VERSION is used for the value of __STDC_VERSION__.
  346. * STDC_HOSTED is used for the value of __STDC_HOSTED__.
  347. */
  348. #if IDMAX < IDLEN90MIN || NBUFF < SLEN90MIN + 3
  349. || NWORK < SLEN90MIN + 2 || NMACPARS < NMACPARS90MIN
  350. || NEXP < EXP_NEST90MIN || BLK_NEST < BLK_NEST90MIN
  351. #define STDC 0
  352. #endif
  353. #ifndef STDC
  354. #define STDC 1 /* 1 : for ISO 9899:1990 or later */
  355. #endif
  356. #ifndef STDC_VERSION
  357. #define STDC_VERSION 0L /* 199409L : For conforming
  358. implementation to ISO 9899:1990 / Amendment 1:1995
  359. 199901L : For C99 */
  360. #endif
  361. #ifndef STDC_HOSTED
  362. #define STDC_HOSTED 1 /* 1 : for hosted implementation,
  363. 0 : for free-standing implementation (C99 specification) */
  364. #endif
  365. /*
  366. * CPLUS specifies the default value of the pre-defined macro __cplusplus
  367. * for C++ processing.
  368. * The value can be changed by -V<n> option.
  369. */
  370. #define CPLUS 1 /* 199711L for C++ Standard */