⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p2c.man

📁 把pascal程序转成C语言程序 把pascal程序转成C语言程序
💻 MAN
📖 第 1 页 / 共 4 页
字号:
code.  This may be turned on or off around specific constant declarations.Set this to 0 to force.I p2cto make absolutely no assumptions about the constant's value in generatedcode, so that you can change the constant later in the C code withoutinvalidating the translation.  The default is to allow.I p2cto take advantage of its knowledge of a constant's value, such as bygenerating code that assumes the constant is positive..TP.B CharConstsThis governs whether single-character string literals in Pascal.B constdeclarations should be interpreted as characters or strings.  In other words,.I const a='x';will translate to.I #define a 'x'if.BR CharConsts =1(the default), or to.I #define a "x"if.BR CharConsts =0.Note that if.I p2cguesses wrong, the generated code will not be wrong, just uglier.  Forexample, if.I ais written as a character constant but it turns out to be used as astring,.I p2cwill have to write char-to-string conversion code each time the constantis used..TP.B PreserveTypes.I P2cmakes an attempt to retain the original names used for data types.For example,.IP\ \ \ \ \ type foo = integer; bar = integer;.IPestablishes two synonyms for the standard integer type;.I p2cdoes its best to preserve the particular synonym that was used todeclare each integer variable.  Because the Pascal language treatsthese types as indistinguishable, there will be cases in thetranslation where.I p2cmust fall back on the "true" type,.BR int ..B PreserveTypesand a few related options control whether various kinds of typenames are preserved.  The default settings preserve all type namesexcept for pointer types, which use "*" notation throught theprogram.  This reflects the fact that Pascal forces pointer typesto be named when traditionally they are not separately named in C..TP.B VarStringsIn HP Pascal, a parameter of the form "var s : string" will match astring variable of any size; a hidden size parameter is passed whichmay be accessed by the Pascal.I strmaxfunction.  You can prevent.I p2cfrom creating a hidden size parameter by setting.BR VarStrings =0.(Note that each function uses the value of.B VarStringsas of the.I firstdeclaration of the function that is parsed, which is often in the interfacesection of a module.).TP.B PrototypesControl whether ANSI C function prototypes are used.  Default is according to.B AnsiCor.BR C++ .This also controls whether to include parameter names or just their typesin situations where names are optional.  The.B FullPrototypingparameter allows prototypes to be generated for declarations but notfor definitions (older versions of Lightspeed C required this).  If youuse a mixture of prototypes and old-style definitions, types like shortand float will be promoted to int and double as required by the ANSIstandard, unless.B PromoteArgsis used to override this.  The.B CastArgsparameter controls whether type-casts are used in function arguments;by default they are used only if prototypes are not available..TP.B StaticLinksHP Pascal and Turbo Pascal each include the concept of procedure orfunction pointers, though with somewhat different syntaxes..I P2crecognizes both notational styles.  Another difference is that HP'sprocedure pointers can point to nested procedures, while Turbo's canpoint only to global procedures.  In HP Pascal a procedure pointer mustbe stored as a.B structcontaining both a pure C function pointer and a "static link," a pointerto the parent procedure's locals.  (The static link is NULL for globalprocedures.)  This notation can be forced by setting.BR StaticLinks =1.In Turbo, the default.RB ( StaticLinks =0)is to use plain C function pointers with no static links.  A third option.RB ( StaticLinks =2)uses structures with static links, but assumes the links are always NULLwhen calling through a pointer (if you need compatibility with the HPformat but know your procedures are global)..TP.B SmallSetConstPascal sets are translated into one of two formats, depending on the sizeof the set.  If all elements have ordinal values in the range 0..31, theset is translated as a single integer variable using bit operations.(The.B SetBitsparameter may be used to change the upper limit of 31.)The.B SmallSetConstparameter controls whether these small-sets are used, and, if so, howconstant sets should be represented in C..IRFor larger sets, an array of.B longis used.  The.IR s [0]element contains the number of succeeding array elementswhich are in use.  Set elements in the range 0..31 are stored in the.IR s [1]array element, and so on.  Sets are normalized so that.IR s [ s [0]]is nonzero for any nonempty set.  The standard run-time libraryincludes all the necessary procedures for operating on sets..TP.B ReturnValueNameThis is one of many "naming conventions" parameters.  Most of thesetake the form of a.IR printf -likestring containing a.I %swhere the relevant information should go.  In the case of.BR ReturnValueName ,the.I %srefers to a function name and the resulting string gives the name ofthe variable to use to hold the function's return value.  Such a variablewill be made if a function contains assignments to its return valueburied within the body, so that.I returnstatements cannot conveniently be used.  Some parameters.RB ( ReturnValueNameincluded) do not require the.I %sto be present in the format string; for example, the standard.I p2crcfile stores every function's return value in a variable called.I Result..TP.B AlternateName.I P2cnormally translates Pascal names into C names verbatim, but occasionallythis is not possible.  A Pascal name may be a C reserved word ortraditional C name like.I putc,or there may be several like-named things that are hidden from each other byPascal's scoping rules but must be global in C.  In these situations.I p2cuses the parameter.B AlternateName1to generate an alternative name for the symbol.  The default is to addan underscore to the name.  There is also an.B AlternateName2parameter for a second alternate name, and an.B AlternateNameparameter for the.IR n thalternate name.  (The value for this parameter should include both a.I %sand a.I %d,in either order.)  If these latter parameters are not defined,.I p2capplies.B AlternateName1many times over..TP.B ExportSymbolSymbols in the interface section for a Pascal module are formattedaccording to the value of.BR ExportSymbol ,if any.  It is not uncommon to use.I modulename_%sfor this symbol; the default is.I %s,i.e., no special treatment for exported symbols.  If you also define the.B Export_Symbolparameter, that format is used instead for exported symbols whichcontain an underscore character.  If.I %S(with a capital "S") appears in the format string it stands for thecurrent module name..TP.B AliasIf the value of this parameter contains a.I %s,it is a format string applied to the names of external functions orvariables.  If the value does not contain a.I %s,it becomes the name of the next external symbol which is declared (afterwhich the parameter is cleared)..TP.B SynonymThis creates a synonym for another Pascal symbol or keyword.  The format is.IP.B "\ \ \ \ \ Synonym".I old-name = new-name.IPAll occurrences of .I old-namein the input text are treated as if they were.I new-nameby the parser.  If.I new-nameis a keyword,.I old-namewill be an equivalent keyword.  If.I new-nameis the name of a predefined function,.I old-namewill behave in the same way as that function, and so on.  If.I new-nameis omitted, then occurrences of.I old-nameare entirely ignored in the input file.  Synonyms allow you to skip overa keyword in your dialect of Pascal that is not understood by.I p2c,or to simulate a keyword or predefined identifier of your dialect with asimilar one that.I p2crecognizes.  Note that all predefined functions are available at all times;if you have a library routine that behaves like, e.g., Turbo Pascal's.I getmemprocedure, you can make your routine a synonym for.I getmemeven if you are not translating in Turbo mode..TP.B NameOfThis defines the name to use in C for a specific symbol.  It must appearbefore the symbol is declared in the Pascal code; it is usually placedin the local.I p2crcfile for the project.  The format is.IP.B "\ \ \ \ \ NameOf".I pascal-name = C-name.IPBy default, Pascal names map directly onto C names with no change(except for the various kinds of formatting outlined above).  If the.I pascal-nameis of the form.I module.nameor.I procedure.namethen the command applies only to the instance of the Pascal name that isglobal to that module, or local to that procedure.  Otherwise, it appliesto all usages of the name..TP.B VarMacroThis is analogous to.BR NameOf ,but specifically for use with Pascal variables.  The righthand side canbe most any C expression; all references to the variable are expandedinto that C expression.  Names used in the C expression are takenverbatim.  There is also a.B ConstMacroparameter for translating constants as arbitrary expressions.Note that the variable on the lefthand side must actually be declaredin the program or in a module that it uses.The declaration for the variable will be omitted from the generated codeunless the Pascal-name appears in the expression:  If you ask toreplace.I iwith.I i+1,the variable.I iwill still be declared but its value will be shifted accordingly.Note that if.I iappears on the lefthand side of an assignment,.I p2cwill use algebra to "solve" for.I i..IPIn all cases where.I p2cparses C expressions, all C operators are recognized except compoundassignments like `+='.  (Increment and decrement operators are allowed.)All variable and function names are assumed to have integer type, evenif they are names that occur in the actual program.  A type-specificationoperator `::' has been introduced; it has the same precedence as `.' or `->'but the righthand side must be a Pascal type identifier (built-in or definedby your program previously to when the macro definition was parsed),or an arbitrary Pascal type expression in parentheses.The lefthand argument is thenconsidered to have the specified type.  This may be necessary if yourmacro is used in situations where the exact type of the expressionmust be known (say, as the argument to a.IR writeln )..TP.B FieldMacroHere the lefthand side must have the form.I record.field,where.I recordis the Pascal type or variable name for a record, and.I fieldis a field in that record.  The righthand side must be a C expressiongenerally including the name.I record.All instances of that name are replaced by the actual record being "dotted."For example,.IP\ \ \ \ \ FieldMacro Rect.topLeft = topLeft(Rect).IPtranslates.I a[i].topLeftinto.I topLeft(a[i]),where.I ais an array of.I Rect..TP.B FuncMacroThe lefthand side must be any Pascal function or procedure name plus aparameter list.  The number of parameters must match the number in thefunction's uses and declaration.  Calls to the function are replaced by theC expression on the righthand side.  For example,.IP\ \ \ \ \ FuncMacro PtInRect(p,r) = PtInRect(p,&r).IPcauses the second argument of.I PtInRectto be passed by reference, even though the declaration says it's not.If the function in question is actually defined in the program or modulebeing translated, the.B FuncMacrowill not affect the definition but it will affect all calls to the functionelsewhere in the module..B FuncMacroscan also be applied to predefined or never-defined functions..TP.B ReplaceBeforeThis option specifies a string replacement to be done on every Pascalsource line.  For example:.IP\ \ \ \ \ ReplaceBefore "{$ifdef" "{EMBED #ifdef"\ \ \ \ \ ReplaceBefore "{$endif}" "{EMBED #endif}".IPThese lines rewrite Turbo Pascal compile-time conditionals intocomments beginning with the special word EMBED.  This word instructsp2c to format the rest of the comment without "/* */" delimiters,i.e., the rest of the comment is embedded directly in the outputC program.  There is also a.B ReplaceAfteroption, which specifies replacements to be done on the output of.I p2c..IPCurrently, this feature makes only literal string replacements,not pattern-based matches.  Some users of.I p2chave found it useful to feed their Pascal programs through a morepowerful editor like.I sedor.I perlbefore giving them to.I p2c.Quite often this is all that is necessary to get an acceptabletranslation in the face of unrecognized Pascal dialects orlanguage features..TP.B IncludeFromThis specifies that a given module's header should be included from agiven place.  The second argument may be surrounded by "\ " or <\ > asnecessary; if the second argument is omitted, no include directive willbe generated for the module..TP.B ImportFromThis specifies that a given module's Pascal interface text can be foundin the given file.  The named file should be either the source file forthe module, or a specially prepared file with the implementation sectionremoved for speed.  If no.B ImportFromentry is found for a module, the path defined by the.B ImportDirlist is searched.  Each entry in the path may contain a.I %s,which expands to the name of the module.  The default path looks for.I %s.pasand.I %s.textin the current directory, then for.I --HOMEDIR--/%s.imp.(where --HOMEDIR-- is the.I p2chome directory.).TP.B StructFunctionThis parameter is a list of functions which follow the.I p2csemantics for structure-valued functions (functions returning arrays,sets, and strings, and structs in primitive C dialects).  For thesefunctions, a pointer to a return-value area is passed to the functionas a special first parameter.  The function stores the result in thisarea, then returns a copy of the pointer.  (The standard C function.I strcpyis an example of this concept..I Sprintfalso behaves this way in some dialects; it always appears on the.B StructFunctionlist regardless of the type of implementation.)  The system configurationfile includes a list of common structured functions so that.IR p2c 'soptimizer will know how to manipulate them.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -