Copyright (C) 1994, Digital Equipment Corp. INTERFACEThis is not intended as a client interface, but as support for the implementation of a tree copy interface.AST_CopyRep ;
ASTCopy is one such
interface. All AST nodes must provide an implementation of the copy
method.
IMPORT AST, AST_WalkRep;
TYPE
NODE = AST_WalkRep.NODE OBJECT
METHODS
copy(handle: Handle): AST.NODE RAISES ANY := Null;
END;
REVEAL AST.NODE <: NODE;
TYPE
Handle <: Handle_public;
Handle_public = OBJECT
METHODS
Copy(n: AST.NODE): AST.NODE RAISES ANY;
END;
PROCEDURE Null(n: NODE; handle: Handle): AST.NODE RAISES {};
returns NIL; used as the default method END AST_CopyRep.The
copy method returns a copy of some part of the tree rooted at
the node making the call. At this level of abstraction copy is very
loosely defined. Precisely which attributes are copied, and whether
attributes are {\em shallow-copied} or {\em deep-copied} is left to
specific AST interfaces to define.
To aid in the creation of flexible copying interfaces, the copy
method takes a Handle argument, in a similar style to the walk
method defined in AST_WalkRep. Each implementation of the copy
method should create a new instance of itself and then apply
handle.Copy to each of its children in turn, children, assigning the
results to the corresponding child attributes of the new instance.