DIRECTORY C2CCodePlaces USING [CodePlace], C2CDefs, IntCodeDefs, IO USING [STREAM], Rope; C2CEmit: CEDAR DEFINITIONS = BEGIN ROPE: TYPE = Rope.ROPE; Precedence: TYPE = C2CDefs.Precedence; Code: TYPE = C2CDefs.Code; breakChar: CHAR = '@; nest: READONLY ROPE; unNest: READONLY ROPE; nestNLine: READONLY ROPE; unNestNLine: READONLY ROPE; line: READONLY ROPE; optionalLine: READONLY ROPE; twoLines: READONLY ROPE; noIndent: READONLY ROPE; CodeOrRope: TYPE = REF; Internalize: PROC [r: ROPE] RETURNS [ROPE]; CComment: PROC [r: ROPE] RETURNS [Code]; Parentize: PROC [c: CodeOrRope] RETURNS [Code]; ParentizeAndLn: PROC [c: CodeOrRope] RETURNS [Code]; NonEmpty: PROC [c: Code] RETURNS [BOOL]; NonWhiteSpace: PROC [c: Code] RETURNS [BOOL]; SetWhiteSpace: PROC [c: Code] RETURNS [sameButModifiedInPlace: Code]; SetArithClass: PROC [c: Code, class: IntCodeDefs.ArithClass] RETURNS [sameCode: Code]; GetArithClass: PROC [c: Code] RETURNS [class: IntCodeDefs.ArithClass]; SetPrecedence: PROC [c: Code, precedence: Precedence ฌ parenPrecedence] RETURNS [sameCode: Code]; SetAddressable: PROC [c: Code, addressable: BOOL ฌ TRUE] RETURNS [sameCode: Code]; SetIsAddress: PROC [c: Code, isAddress: BOOL ฌ TRUE] RETURNS [sameCode: Code]; GetPrecedence: PROC [c: Code] RETURNS [precedence: Precedence]; GetAddressable: PROC [c: Code] RETURNS [addressable: BOOL]; GetIsAddress: PROC [c: Code] RETURNS [isAddress: BOOL]; SetDead: PROC [c: Code, dead: BOOL ฌ TRUE]; GetIsDead: PROC [c: Code] RETURNS [BOOL]; Deref: PROC [c: Code, pointeeBits: INT] RETURNS [Code]; IsDelayedDeref: PROC [c: Code] RETURNS [BOOL]; TakeAddr: PROC [c: Code, preventCastingToWord: BOOL ฌ FALSE] RETURNS [Code]; PreventCastingToWord: PROC [c: Code] RETURNS [Code]; CastWord: PROC [c: CodeOrRope] RETURNS [Code]; CastRef: PROC [c: Code, pointeeBits: INT] RETURNS [Code]; SetWord: PROC [c: Code] RETURNS [Code]; SetRef: PROC [c: Code, pointeeBits: INT] RETURNS [Code]; CodeToRope: PROC [c: CodeOrRope] RETURNS [r: ROPE]; CodeToRopeD: PROC [c: CodeOrRope] RETURNS [r: ROPE]; RopeCode: PROC [r: ROPE ฌ NIL] RETURNS [c: Code]; RefTextCode: PROC [r: REF TEXT ฌ NIL] RETURNS [c: Code]; IdentCode: PROC [r: ROPE ฌ NIL] RETURNS [c: Code]; MinPrecedence: PROC [c: Code, minimum: PrecedenceฌassignPrecedence] RETURNS [modifiedC: Code]; BinOp: PROC [c1: Code, op: ROPE, c2: Code, precedence: Precedence ฌ commaPrecedence] RETURNS [Code]; CopyC: PROC [c: Code] RETURNS [Code]; Cat: PROC [c1, c2, c3, c4, c5: CodeOrRope ฌ NIL] RETURNS [Code]; CatCall: PROC [function: ROPE, c1, c2, c3, c4, c5: CodeOrRope ฌ NIL] RETURNS [Code]; CatRemark: PROC [c: Code, r: ROPE] RETURNS [Code]; CatDebugInfo: PROC [c: Code, r: ROPE, key: REF ฌ NIL] RETURNS [Code]; AppendCode: PROC [place: C2CCodePlaces.CodePlace, code: CodeOrRope]; CollectCode: PROC [place: C2CCodePlaces.CodePlace, final: BOOL ฌ FALSE] RETURNS [c: Code]; ProcessAndOutputCode: PROC [stream: IO.STREAM, lineStream: IO.STREAM, c: Code, lineChar: CHAR ฌ '\n, allowUnIndent: BOOL ฌ TRUE]; END. ( C2CEmit.mesa Copyright ำ 1987, 1988, 1989, 1990, 1991 by Xerox Corporation. All rights reserved. Christian Jacobi, March 23, 1988 5:12:29 pm PST Christian Jacobi, January 29, 1993 11:11 am PST C2C's code emitting primitives --clients must not take advantage of knowledge which character is used --Rope operations --given an external defined rope [maybe containing formatting information] --returns internalized rope which does not fool the formatting --Fine point: For most procedures, ropes must not contain the formatting sequences used internally by C2CEmitImpl. This is no problem since these sequences are defined with the breakChar, which does not occur in C except as literal or comment. In those cases clients must use CComment or ExternalRopeCode to internalize the ropes. --given an rope returns a legal comment in C --[removes characters prematurely terminating a comment] --Code properties --put paranthesis around code --may or may not remove nested parenthesis --put paranthesis around code and some line breaks --may or may not remove nested parenthesis --test whether code is empty or NIL --non destructive --test whether code is empty, NIL, or contains only whitespace --non destructive --declares code to be white space only --ArithClass used to describ the type of the actual C code; (not intendet type) --Note: The generated C code will have the right bits, but it might not have --the type as requested in the IntCode. --Exception: kind=signed means type is unsigned, but gives position of sign bit. --usage restricted to access of arrays as a whole --isAdress means "code is the adress of what you actually wanted" --[~isAdress does not mean that code wouldn't be an adress] --non destructive --dead code: the following code won't be executed, unless it starts with a label --deadness is a hint: deadness can get lost, but must never be claimed wrongly --concatenating code inherits deadness from last nonempty piece --Delayed Code handling --makes a de-referrencing, delayed --pointeeBits: cast any pointer type to the required pointer type pointing to pointeeBits --like * (pointerType) (code) --Sets precedence to unary ! --destructive --if true TakeAddr will not cause a "&" to appear! --returns something like &c --preventCastingToWord: code stays of type address --should code be of type address it will stay... -- puts (word) in front -- destructive on c! if Code -- handles precedence -- assumes precedence high enough if ROPE -- Client must not know whether cast is allways made or sometimes optimized away -- like (pointerType) (code) -- may be destructive on c -- handles precedence -- Client must not know whether cast is allways made or sometimes optimized away -- declares c to be of type word -- may be destructive on c -- declares c to be of type ref to pointeeBits -- may be destructive on c --Code operations --returns rope representing Code; --returned rope inclusive delayed state but, c is not modified --non destructive --returns rope representing Code; --returned rope inclusive delayed state --c is destroyed and returned --returns new code representing rope; Precedence notExpressionPrecedence --returns new code representing rope; Precedence notExpressionPrecedence --returns new code representing rope; Precedence identPrecedence; addressable --Guarantees minimum precedence by adding parantheses --reuses and modifies c^ --might or might not reuses and modifies either c^! --makes a real, new copy of code; c^ not changed --non destructive --concatenates code pieces --each code piece a rope, ref text or code for conveniance --might or might not reuses and modifies either code pieces if is of type code --Catenates function name, codes in parantheses and makes primary precedence --might or might not reuses and modifies either c^! --appends a remark to code --might or might not reuses and modifies c^! --adds only comment to code; does not change addressability precedence ... --Optionally appends debugging information to code (if not empty) for the purpose --of debugging C2C. (depending on compiler switches) --Might or might not reuses and modifies c^! --Collection of Code --appends code to stated purpose --code may or may not be cleared --returns the code generated for that place and empties the place --removes formatting instructions of code --and produces final rope --may be destructive ส๙–(cedarcode) style•NewlineDelimiter ™šœ ™ Icodešœ ฯeœI™TKšœ/™/K™/K™K™K™—šฯk ˜ Kšœžœ ˜ Kšœ˜Kšœ ˜ Kšžœžœžœ˜Kšœ˜K˜—Kšฯnœžœž œ˜šž˜Iimp˜Kšžœžœžœ˜Kšœ žœ˜&Kšœžœ˜L˜šœ žœ˜LšœG™G—Lšœžœžœ˜Lšœžœžœ˜Lšœ žœžœ˜Lšœ žœžœ˜Lšœžœžœ˜Lšœžœžœ˜Lšœ žœžœ˜Lšœ žœžœ˜L˜Lšœ žœžœ˜—K˜K˜šะbc™K˜š Ÿ œžœžœžœžœ˜+LšฯcJ™JLšœ>™>™ Jšฯsฟ™ฟK™——šŸœžœžœžœ˜(Lšก,™,Lšกœ7™9—L™K˜—š ฯb™K˜šŸ œžœžœ˜/K™K™*—K˜šŸœžœžœ˜4K™2K™*K˜—šŸœžœ žœžœ˜(Kšก#™#Kšก™K˜—šŸ œžœ žœžœ˜-Kšก>™>Kšก™K˜—šŸ œžœ žœ ˜EKšก&™&K˜—KšŸ œžœ*žœ˜VšŸ œžœ žœ!˜FKšก- ก™OKšกL™LKšก'™'KšœP™P—K˜K˜KšŸ œžœ5žœ˜aKš Ÿœžœžœžœžœ˜Rš Ÿ œžœžœžœžœ˜NKšœ1™1—K˜KšŸ œžœ žœ˜?KšŸœžœ žœžœ˜;šŸ œžœ žœ žœ˜7KšœA™AKšœ;™;Kšœก ™—K˜KšŸœžœžœžœ˜+šŸ œžœ žœžœ˜)KšกP™PKšกN™NKšก?™?K™——š ™K˜šŸœžœžœžœ˜7Lšก"™"LšกZ™ZLšก™Lšก™Lšก ™ L˜—šŸœžœ žœžœ˜.Kšœ2™2—K˜š Ÿœžœ!žœžœžœ˜LKšก™Kšก2™2K˜—šŸœžœ žœ˜4Kšก0™0L˜—šŸœžœžœ˜.Lšก™Lšก™Lšก™Lšก)™)LšกQ™QL™—šŸœžœžœžœ˜9Lšก™Lšก™Lšก™LšกQ™QL™—šŸœžœ žœ˜'Lšก ™ Lšก™L™—šŸœžœžœžœ˜8Lšก#œ ™.Lšก™L™——L™šฃ™L˜šŸ œžœžœžœ˜3Kšก"™"Kšก>™>Kšœก ™K™—šŸ œžœžœžœ˜4Kšก"™"Kšก'™'Kšœ™—L˜š Ÿœžœžœžœžœ ˜1KšกH™HL˜—š Ÿ œžœžœžœžœžœ ˜8KšกH™HL˜—š Ÿ œžœžœžœžœ ˜2KšกM™ML˜—šŸ œžœ1žœ˜^Kšก5™5Kšกœก™K˜—šŸœžœžœ6žœ˜dKšก3™3K˜—šŸœžœ žœ˜%Kšก0™0Kšœก ™K˜—šŸœžœ#žœžœ˜@Kšก™Kšก:™:KšกN™N—K˜š Ÿœžœ žœ#žœžœ˜TKšกL™LKšก3™3K˜—šŸ œžœžœžœ˜2Kšก™Kšก,™,KšกJ™JK™—š Ÿ œžœžœžœžœžœ˜EKšกR™RKšก5™5Kšก,™,——™K˜—šฃ™K˜šŸ œžœ4˜DL™ Lšœ ™ —L˜š Ÿ œžœ)žœžœžœ ˜ZLšœB™BL™——™L˜šŸœžœ žœžœžœžœžœžœžœ˜Kšก)™)Kšก™Kšœ™——L˜Lšžœ˜K˜—…— า$๓