NOTES
上传用户:upcnvip
上传日期:2007-01-06
资源大小:474k
文件大小:32k
- THE GRAND P2C NOTES FILE:
- This file contains notes to myself recording bugs, flaws, and suggested
- improvements to p2c. They have roughly been separated into "old", "older",
- and "oldest" groups. I can't guarantee I'll do any of these. If you do,
- please mail me the diffs so I can incorporate them into the next release.
- Thanks!
- -- Dave Gillespie
- daveg@csvax.caltech.edu
- -----------------------------------------------------------------------------
- The Pascal declaration
- type foo = set of (one, two);
- does not ever write out an "enum { one, two }" declaration in C!
- -----------------------------------------------------------------------------
- Handling of comments that trail the ELSE clause of an IF statement
- could use some work.
- -----------------------------------------------------------------------------
- Technically speaking, "for byte := min to max do" is legal even
- if min > 255, i.e., the limits only need to be in range if the
- body of the loop executes. Thus, FOR loops should really use a
- shadow parameter not just when max is the constant 255, but
- whenever min or max are not provably in byte range.
- -----------------------------------------------------------------------------
- Have a "-M"-like mode in which FREE is suppressed altogether, useful
- in case p2c crashes because bugs have corrupted malloc's free list.
- -----------------------------------------------------------------------------
- For expressions building small-sets whose maximum element is <= 15,
- use "1 << x" instead of "1L << x".
- -----------------------------------------------------------------------------
- Handle VAX Pascal VARYING OF CHARs used as the arguments of WITH
- statements.
- -----------------------------------------------------------------------------
- Have a p2crc feature which identifies a given named constant as
- being a character, not a string of length 1. Have an option in
- which this is the default interpretation.
- -----------------------------------------------------------------------------
- StringTruncLimit would be helped by expr.c:strmax() interpreting
- sprintf control strings. For %s, use strmax of the corresponding
- argument. For %d, use 11, etc. For %.10s, use min(10, strmax(arg)).
- For %.*s, just use strmax(arg), I guess.
- Have a mode in which such assignments are automatically truncated.
- Perform truncation testing for non-VAR procedure arguments, too.
- -----------------------------------------------------------------------------
- In cref.p, the "strappend(buf,#0)" statement translates into
- "strcpy(STR1,buf); strcpy(buf,STR1)" with a warning about a null
- character in a sprintf control string!
- -----------------------------------------------------------------------------
- Still having problems where the opening comment of an imported
- module's interface text is copied into the program.
- -----------------------------------------------------------------------------
- VAX Pascal features not yet handled:
- [UNSAFE] attribute is only implemented in a few situations.
- [UNBOUND] attribute on a procedure says it doesn't need a static link.
- [TRUNCATE] attribute on a parameter allows optional params w/no default.
- [LIST] attribute on a parameter is like &rest in Lisp.
- Support types like, e.g., [LONG] BOOLEAN.
- Can assign "structurally compatible" but different record types.
- File intrinsics need serious work, especially OPEN.
- If a copy param is [READONLY], don't need to copy it.
- If a procedure is [ASYNCHRONOUS], make all its variables volatile.
- If a procedure is [NOOPTIMIZE], make all its variables volatile.
- Provide a real implementation of BIN function and :BIN read format.
- BIT_OFFSET and CARD intrinsics are not supported.
- -----------------------------------------------------------------------------
- Modula-2 features not yet handled:
- Local modules are faked up in a pretty superficial way.
- WORD is compatible with both pointers and CARDINALs.
- WORD parameters are compatible with any word-sized object.
- ARRAY OF WORD parameters are compatible with absolutely anything.
- Improve treatment of character strings.
- Find manuals for real implementations of Modula-2 and implement
- any common language extensions.
- Fix p2c to read system.m2 instead of system.imp automatically.
- -----------------------------------------------------------------------------
- Oregon Software Pascal features not yet handled:
- procedure noioerror(var f:file);
- Built-in. Sets a flag on an already-open file so that
- I/O errors record an error code rather than crashing.
- Each file has its own error code.
- function ioerror(var f:file) : boolean;
- True if an error has occurred in the file.
- function iostatus(var f:file) : integer;
- The error code, when ioerror was true.
- reset and rewrite ignore the third parameter, and allow a fourth
- param which is an integer variable that receives a status code.
- Without this param, open errors are fatal. An optional param
- may be omitted as in reset(f,'foo',,v);
- -----------------------------------------------------------------------------
- In p_search, if a file contains const/var/type/procedure/function
- declarations without any module declaration, surround the entire
- file with an implicit "module <generated-name>; {PERMANENT}" ... "end.".
- This would help the Oregon Software dialect considerably.
- -----------------------------------------------------------------------------
- Provide an explicit IncludeFrom syntax for "no include file".
- E.g., "IncludeFrom dos 0".
- -----------------------------------------------------------------------------
- In docast, smallsets are converted to large sets of the requested type.
- Wouldn't it be better to convert to a set of 0..31 of the base type?
- This would keep foo([]), where the argument is "set of char", from
- allocating a full 256-bit array for the temporary.
- -----------------------------------------------------------------------------
- When initializing a constant variant record or array of same in which
- non-first variants are initialized, create a function to do the
- initialization, plus, for modules w/o initializers, a note to call
- this function. Another possibility: Initialize the array as well as
- possible, but leave zeros in the variant parts. Then the function
- has only to fix up the non-first variant fields.
- -----------------------------------------------------------------------------
- Figure out some way to initialize packed array constants, e.g., a short
- macro PACK4(x,y)=(((x)<<4)+(y)) which is used inside the C initializer.
- Alternatively, implement initializer functions as above and use those.
- -----------------------------------------------------------------------------
- How about declaring Volatile any variables local to a function which
- are used after the first RECOVER? GNU also suggests writing the
- statement: "&foo;" which will have no side effect except to make
- foo essentially volatile, without relying on ANSI features.
- -----------------------------------------------------------------------------
- Test the macros for GET, PUT, etc.
- -----------------------------------------------------------------------------
- Can the #if 0'd code for strinsert in funcs.c be changed to test
- strcpyleft?
- -----------------------------------------------------------------------------
- Even in Ansi mode, p2c seems to be casting Anyptrs into other pointer
- types explicitly. This is an automatic conversion in Ansi C.
- -----------------------------------------------------------------------------
- A Turbo typed constant or VAX initialized variable with a VarMacro
- loses its initializer!
- -----------------------------------------------------------------------------
- Test the ability of the parser to recover from common problems such
- as too many/few arguments to a procedure, missing/extra semicolon, etc.
- One major problem has been with undeclared identifiers being used as
- type names.
- -----------------------------------------------------------------------------
- Line breaker still needs considerable tuning!
- -----------------------------------------------------------------------------
- How about indenting trailing comments analogously to the code:
- Try to indent to column C+(X-Y), where C=original column number,
- X=output indentation, Y=original input indentation.
- Even fancier would be to study all the comment indentations in the
- function or struct decl to discover if most comments are at the same
- absolute indentation; if so, compute the average or minimum amount of
- space preceding the comments and indent the C comments to an analogous
- position.
- -----------------------------------------------------------------------------
- After "type foo = bar;" variables declared as type foo are translated
- as type bar. Ought to assume the user has two names for a reason,
- and copy the distinction into the C code.
- -----------------------------------------------------------------------------
- Warn if address is taken of an arithmetic expression like "v1+1".
- Allow user to declare certain bicalls as l-values, e.g., so that
- LSC's topLeft and botRight macros won't generate complaints.
- -----------------------------------------------------------------------------
- Consider changing the "language" modes into a set of p2crc files
- which can be included to support the various modes.
- -----------------------------------------------------------------------------
- If we exchange the THEN and ELSE parts of an IF statement, be sure
- to exchange their comments as well!
- -----------------------------------------------------------------------------
- How about checking for a ".p2crc" file in the user's home directory.
- -----------------------------------------------------------------------------
- Store comments in the following situations:
- On the first line of a record decl.
- On the default clause of a CASE statement
- (use same trick as for ELSE clauses).
- On the "end" of a CASE statement.
- On null statements.
- Use stealcomments for, e.g., decl_comments and others.
- -----------------------------------------------------------------------------
- Think of other formatting options for format_gen to support.
- -----------------------------------------------------------------------------
- Consider converting gratuitous BEGIN/END pairs into gratuitous
- { } pairs.
- -----------------------------------------------------------------------------
- The construction "s := copy(s, 1, 3)" converts to a big mess that
- could be simplified to "s[3] = 0".
- -----------------------------------------------------------------------------
- Have a mode (and make it the default!) in which declarations are mixed
- if and only if the original Pascal decls were mixed. Simply store
- a flag in each meaning to mark "mixed-with-preceding-meaning".
- -----------------------------------------------------------------------------
- Have a column number at which to put names in variable and typedef
- declarations. Have another option to choose whether a '*' preceding
- a name should be left- or right-justified within the skipped space:
- int *foo; or
- int * foo;
- -----------------------------------------------------------------------------
- Support the /*
- *
- */ form for multi-line comments.
- -----------------------------------------------------------------------------
- Have an indentation parameter for the word "else" by itself on a line.
- -----------------------------------------------------------------------------
- Have an option to use C++'s "//" comments when possible.
- (0=never, 1=always, def=only for trailing comments.)
- -----------------------------------------------------------------------------
- Allow real comments to come before top-of-file comments like {Language}.
- -----------------------------------------------------------------------------
- Teach the line breaker to remove spaces around innermost operators
- if in a crunch.
- -----------------------------------------------------------------------------
- Is it possible that the line breaker is losing counts? A line that
- included lots of invisible parens converted to visible ones was
- allowed to be suspiciously long.
- -----------------------------------------------------------------------------
- The notation t^ where t is a text file should convert n's to
- spaces if necessary.
- -----------------------------------------------------------------------------
- The assignment and type cast "f4 := tf4(i)" where type
- "tf4 = function (i, j : integer) : str255"
- generates something really weird.
- -----------------------------------------------------------------------------
- The conditional expression strsub(s,1,4) = 'Spam'
- could be translated as strncmp(s, "Spam", 4)
- -----------------------------------------------------------------------------
- Consider an option which generates a "file.p2c" or "module.p2c"
- file, that will in the future be read in by p2c as another p2crc
- type of file, both when the module is re-translated later and when
- it is imported. This file would contain commands like "NoSideEffects"
- for functions which are found to have this property, etc.
- -----------------------------------------------------------------------------
- Extend the "file.log" or "module.log" file to contain a more detailed
- account of the translation, including all notes and warnings which were
- even considered. For example, ALL calls to na_lsl with non-constant
- shifts would be noted, even if regular notes in this case were not
- requested. Also, funny transformations along the lines of
- "str[0] := chr(len)" and "ch >= #128" should be mentioned in the log.
- How about a summary of non-default p2crc options and command-line args?
- -----------------------------------------------------------------------------
- Create a TypeMacro analogous to FuncMacro, VarMacro, and ConstMacro.
- Should the definition be expressed in C or Pascal notation? (Yuck---not
- a C type parser!)
- -----------------------------------------------------------------------------
- In argument type promotions, should "unsigned char" be promoted to
- "unsigned int"?
- -----------------------------------------------------------------------------
- Turbo's FExpand translation is really weird.
- -----------------------------------------------------------------------------
- Can we translate Erase(x) to unlink(x)? (This could just be a FuncMacro.)
- -----------------------------------------------------------------------------
- There should be an option that causes a type to be explicitly named,
- even if it would not otherwise have had a typedef name. Have a mode
- that does this for all pointer types.
- -----------------------------------------------------------------------------
- Make sure that the construction: if blah then {comment} else other
- does not rewrite to if (!blah) other; i.e., a comment in this situation
- should generate an actual placeholder statement. Or perhaps, a null
- statement written explicitly by the Pascal programmer should always
- produce a placeholder.
- -----------------------------------------------------------------------------
- Allow the line breaker to treat a