comp.lang.ada
 help / color / mirror / Atom feed
* issue with implementing a visitor design pattern
@ 2004-01-15 19:22 cl1
  2004-01-17  3:41 ` Robert I. Eachus
  0 siblings, 1 reply; 10+ messages in thread
From: cl1 @ 2004-01-15 19:22 UTC (permalink / raw)


i'm trying to implement a visitor pattern for a parse tree(its a simple
calculator at this point). i have an abstract type:

type Visitor_Record is abstract tagged null record;

with primative operations Visit() for each node type like so:

Visit(V : in out Visitor_Record; Node : in Add_Op'Class) is abstract;
...
Visit(V : in out Visitor_Record; Node : in Assignment_Node'Class) is
abstract;

what i'm trying to do is implement a Preorder_Visitor_Record type that uses
the Visit() operation to
traverse the tree and calls an operation Visit_Operation() that is also a
primative operation on Preorder_Visitor_Record
like so:
with parse_tree_pkg; use parse_tree_pkg; -- has the parse tree nodes a
primative operation Accept_Visitor() for each node
                                                                 -- and the
abstract Visitor_Record with primative operations Visit() for each node
package Preorder_Visitor_Pkg is
    type Preorder_Visitor_Record is new Visitor_Record with null record;

    -- this is overidiing the abstract version in parse_tree_pkg;
    procedure Visit ( V : in out Preorder_Visitor_Record; Node : in
Add_Op'Class);
    .....

    procedure Visit_Operation (V : in preorder_Visitor_Record; node : in
add_op'class);
end preorder_visitor_Pkg;

package body Preorder_Visitor_Pkg is

procedure Visit_Operation ( V : in out Preorder_Visitor_Record; Node : in
Add_Op'Class)
is begin
    raise Not_Implemented; -- better handling in actual code with an error
message using ada.exceptions
end Visit_Operation
procedure Visit( V : in out Preorder_Visitor_Record; Node : in Add_Op'Class)
is begin
    Visit_Operation(V, Node);
end Visit;


the actual code errors saying ambiguos call of Visit_Operation() from within
the Visit() procedure. with possible interpretations at the definition of
Preorder_Visitor_Record and at the specification for Visit_Operation.

the code works when you take Visit_Operation out of the mix. the package
compiles and works with a test driver. but when i try to add in this
Visit_Operation it doesn't work. I don't know if there are some scoping
issues or if there is something else i need to know about primative
operations to make this work. any guidance would be appreciated.

Thanks,
Charles Lambert





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-02-01  0:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-01-15 19:22 issue with implementing a visitor design pattern cl1
2004-01-17  3:41 ` Robert I. Eachus
2004-01-17 21:24   ` Robert A Duff
2004-01-24 20:38     ` Dale Stanbrough
2004-01-24 21:44       ` Robert A Duff
2004-01-26  8:34         ` Dmitry A. Kazakov
2004-01-26 20:18           ` Robert A Duff
2004-01-27  8:36             ` Dmitry A. Kazakov
2004-02-01  0:32               ` Georg Bauhaus
2004-01-17 23:05   ` cl1

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox