📄 p2c.cat
字号:
macros in the file _p_2_c._h which all translated programs include. You can set UseAnyptrMac- ros=0 to disable the use of these macros. Note that the functions of many of these mac- ros can also be had directly using other parameters; for example, UseConsts allows you to specify whether your target language recognizes the word const in constant declarations. The default is to use the Const macro instead, so that your code will be portable to either kind of implementation. Signed expands to the reserved word signed if that word is available, otherwise it is given a null definition. Similarly, Const expands to const if that feature is available. The words Volatile and Register are also definedSun Release 4.1 Last change: local 9P2C(1) USER COMMANDS P2C(1) in _p_2_c._h, although _p_2_c does not use them at present. The word Char expands to char by default, but might need to be redefined to signed char or unsigned char in a particular implementation. This is used for the Pascal character type; lowercase char is used when the desired meaning is "byte," not "charac- ter." The word Static always expands to static by default. This is used in situations where a function or variable is declared static to make it local to the source file; lowercase static is used for static local variables. Thus you can redefine Static to be null if you want to force private names to be public for purposes of debugging. The word Void expands to void in all cases; it is used when declaring a function with no return value. The word Anyptr is a typedef for void * or char * as necessary; it represents a generic pointer. UsePPMacros The _p_2_c._h header also declares two macros for function prototyping, PP(x) and PV(). These macros are used as follows: Void foo PP( (int x, int y, Char *z) ); Char *bar PV( ); If prototypes are available, these macros will expand to Void foo (int x, int y, Char *z); Char *bar (void); but if only old-style declarations are sup- ported, you instead get Void foo (); Char *bar (); By default, _p_2_c uses these macros for all function declarations, but function _d_e_f_i_n_i_- _t_i_o_n_s are written in old-style C. The UsePP- Macros parameter can be set to 0 to disable all use of PP and PV, or it can be set to 1 to use the macros even when defining a func- tion. (This is accomplished by preceding each old-style definition with a PP-style declaration.) If you know your code willSun Release 4.1 Last change: local 10P2C(1) USER COMMANDS P2C(1) always be compiled on systems that support prototyping, it is prettier to set Proto- types=1 or simply AnsiC=1 to get true func- tion prototypes. EatNotes Notes and warning messages containing any of these strings as sub-strings are not emitted. Each type of message includes an identifier like [145]; you can add this identifier to the EatNotes list to suppress that message. Another useful form is to use a variable name or other identifier to suppress warnings about that variable. The strings are a space-separated list, and thus may not con- tain embedded spaces. To suppress notes around a section of code, use, e.g., {_E_a_t_- _N_o_t_e_s+[_1_4_5]} and {_E_a_t_N_o_t_e_s-[_1_4_5]}. Most notes are generated during parsing, but to suppress those generated during output the string may need to remain in the list far beyond the point where it appears to be generated. Use the string "1" or "0" to disable or enable all notes, respectively. ExpandIncludes The default action is to expand Pascal include files in-line. This may not be desirable if include files are being used to simulate modules. With ExpandIncludes=0, _p_2_c attempts to convert include files containing only whole procedures and global declarations into analogous C include files. This may not always work, though; if you get error mes- sages, don't use this option. By combining this option with StaticFunctions=0, then doing some fairly minor editing on the result, you can convert a pseudo-modular Pas- cal program into a truly modular collection of C source files. ElimDeadCode Some transformations that _p_2_c does on the program may result in unreachable or "dead" code. By default _p_2_c removes such code, but sometimes it removes more than it should. If you have "if false" segments which you wish to retain in C, you may have to set ElimDead- Code=0. AnalyzeFlow By default _p_2_c does some basic dataflow analysis on the program in an attempt to locate code that can be simplified due to knowledge about the possible values of cer- tain variables. For example, a PascalSun Release 4.1 Last change: local 11P2C(1) USER COMMANDS P2C(1) rewrite statement must translate to an if that either calls fopen on a formerly closed file variable, or freopen on an already-open file. If flow analysis can prove that the file was open or closed upon entry to the statement, a much cleaner translation is pos- sible. It is possible that flow analysis will make simplifications that are undesirable or buggy. If this occurs, you can set AnalyzeFlow to 0 to disable this feature. SkipIndices Normally Pascal arrays not based at zero are "shifted" down for C, preserving the total size of the array. A Pascal array a[2..10] is translated to a C array a[9] with refer- ences like "a[i]" changed to "a[i-2]" every- where. If SkipIndices is set to a value of 2 or higher, this array would instead be translated to a[11] with the first two ele- ments never used. This arrangement may gen- erate incorrect code, though, for tricky source programs. FoldConstants Pascal non-structured constants generally translate to #define's in C. Set this to 1 to have constants instantiated directly into the code. This may be turned on or off around specific constant declarations. Set this to 0 to force _p_2_c to make absolutely no assumptions about the constant's value in generated code, so that you can change the constant later in the C code without invali- dating the translation. The default is to allow _p_2_c to take advantage of its knowledge of a constant's value, such as by generating code that assumes the constant is positive. CharConsts This governs whether single-character string literals in Pascal const declarations should be interpreted as characters or strings. In other words, _c_o_n_s_t _a='_x'; will translate to #_d_e_f_i_n_e _a '_x' if CharConsts=1 (the default), or to #_d_e_f_i_n_e _a _x if CharConsts=0. Note that if _p_2_c guesses wrong, the generated code will not be wrong, just uglier. For example, if _a is written as a character constant but it turns out to be used as a string, _p_2_c will have to write char-to-string conversion code each time the constant is used.Sun Release 4.1 Last change: local 12P2C(1) USER COMMANDS P2C(1) PreserveTypes _P_2_c makes an attempt to retain the original names used for data types. For example, type foo = integer; bar = integer; establishes two synonyms for the standard integer type; _p_2_c does its best to preserve the particular synonym that was used to declare each integer variable. Because the Pascal language treats these types as indis- tinguishable, there will be cases in the translation where _p_2_c must fall back on the "true" type, int. PreserveTypes and a few related options control whether various kinds of type names are preserved. The default settings preserve all type names except for pointer types, which use "*" notation throught the program. This reflects the fact that Pascal forces pointer types to be named when traditionally they are not separately named in C. VarStrings In HP Pascal, a parameter of the form "var s : string" will match a string variable of any size; a hidden size parameter is passed which may be accessed by the Pascal _s_t_r_m_a_x func- tion. You can prevent _p_2_c from creating a hidden size parameter by setting Var- Strings=0. (Note that each function uses the value of VarStrings as of the _f_i_r_s_t declara- tion of the function that is parsed, which is often in the interface section of a module.) Prototypes Control whether ANSI C function prototypes are used. Default is according to AnsiC or C++. This also controls whether to include parameter names or just their types in situa- tions where names are optional. The FullPro- totyping parameter allows prototypes to be generated for declarations but not for defin- itions (older versions of Lightspeed C required this). If you use a mixture of pro- totypes and old-style definitions, types like short and float will be promoted to int and double as required by the ANSI standard, unless PromoteArgs is used to override this. The CastArgs parameter controls whether type-casts are used in function arguments; by default they are used only if prototypes are not available. StaticLinks HP Pascal and Turbo Pascal each include theSun Release 4.1 Last change: local 13
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -