File: Synopsis/SymbolLookup/Walker.hh
 1//
 2// Copyright (C) 2004 Stefan Seefeld
 3// All rights reserved.
 4// Licensed to the public under the terms of the GNU LGPL (>= 2),
 5// see the file COPYING for details.
 6//
 7#ifndef Synopsis_SymbolLookup_Walker_hh_
 8#define Synopsis_SymbolLookup_Walker_hh_
 9
10#include <Synopsis/PTree.hh>
11#include <Synopsis/SymbolLookup/Scope.hh>
12#include <stack>
13
14namespace Synopsis
15{
16namespace SymbolLookup
17{
18
19//. This Walker adjusts the symbol lookup table while the parse tree
20//. is being traversed such that symbols in the parse tree can be
21//. looked up correctly in the right context.
22class Walker : public PTree::Visitor
23{
24public:
25  Walker(Scope *);
26  virtual ~Walker();
27
28  using PTree::Visitor::visit;
29  virtual void visit(PTree::List *);
30  virtual void visit(PTree::Block *);
31  virtual void visit(PTree::TemplateDecl *);
32  virtual void visit(PTree::NamespaceSpec *);
33  virtual void visit(PTree::FunctionDefinition *);
34  virtual void visit(PTree::ClassSpec *);
35  virtual void visit(PTree::DotMemberExpr *);
36  virtual void visit(PTree::ArrowMemberExpr *);
37
38  //. Traverse the body of a namespace definition.
39  void traverse_body(PTree::NamespaceSpec *);
40  //. Traverse the body of the class definition.
41  void traverse_body(PTree::ClassSpec *);
42  //. Traverse the template parameter list of a template declaration.
43  void traverse_parameters(PTree::TemplateDecl *);
44  //. Traverse the body of the function definition.
45  void traverse_body(PTree::FunctionDefinition *);
46
47protected:
48  Scope const *current_scope() { return my_scopes.top();}
49  void leave_scope();
50private:
51  typedef std::stack<Scope *> Scopes;
52
53  //. the virtual visit(Block) version above does scoping,
54  //. which isn't what we want if traversing a function (FIXME: or is it ?)
55  //. so the following factors out the common code.
56  void visit_block(PTree::Block *);
57  //. The symbol lookup table.
58  Scopes  my_scopes;
59};
60
61}
62}
63
64#endif