File: Synopsis/SymbolFactory.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_SymbolFactory_hh_
 8#define Synopsis_SymbolFactory_hh_
 9
10#include <Synopsis/SymbolLookup/Scope.hh>
11#include <stack>
12
13namespace Synopsis
14{
15namespace SymbolLookup
16{
17class PrototypeScope;
18class TemplateParameterScope;
19}
20
21//. SymbolFactory populates a symbol table.
22class SymbolFactory
23{
24public:
25  //.
26  enum Language { NONE = 0x00, C99 = 0x01, CXX = 0x02};
27
28  //. Create a symbol lookup table for the given language.
29  //. Right now only CXX is supported.
30  SymbolFactory(Language = CXX);
31
32  SymbolLookup::Scope *current_scope() { return my_scopes.top();}
33
34  void enter_scope(PTree::NamespaceSpec const *);
35  void enter_scope(PTree::ClassSpec const *);
36  void enter_scope(PTree::Node const *);
37  void enter_scope(PTree::FunctionDefinition const *);
38  void enter_scope(PTree::TemplateDecl const *);
39  void enter_scope(PTree::Block const *);
40  void leave_scope();
41
42  void declare(PTree::Declaration const *);
43  void declare(PTree::Typedef const *);
44  //. declare the enumeration as a new TYPE as well as all the enumerators as CONST
45  void declare(PTree::EnumSpec const *);
46  //. declare the namespace as a new NAMESPACE
47  void declare(PTree::NamespaceSpec const *);
48  //. declare the class as a new TYPE
49  void declare(PTree::ClassSpec const *);
50  void declare(PTree::TemplateDecl const *);
51  void declare(PTree::TypeParameter const *);
52  void declare(PTree::UsingDirective const *);
53  void declare(PTree::ParameterDeclaration const *);
54  void declare(PTree::UsingDeclaration const *);
55
56private:
57  typedef std::stack<SymbolLookup::Scope *> Scopes;
58
59  //. Lookup the scope of a qualified name.
60  //. The encoded name is modified in place to
61  //. refer to the unqualified name.
62  SymbolLookup::Scope *lookup_scope_of_qname(PTree::Encoding &, PTree::Node const *);
63
64  Language                      my_language;
65  Scopes                        my_scopes;
66  //. When parsing a function definition the declarator is seen first,
67  //. and thus a prototype is created to hold the parameters.
68  //. Later, when the function definition proper is seen, the symbols
69  //. are transfered and the prototype is deleted.
70  SymbolLookup::PrototypeScope *my_prototype;
71  //. When parsing a class or function template the template-parameter-list
72  //. is seen first. Since ClassSpec and Declarator don't know they are part
73  //. of a template declaration, we cache it here so it gets consumed when
74  //. the Class or PrototypeScope are created.
75  // FIXME: Should ClassSpec get a flag so it knows it's a template, similar
76  //        to Encodings helt in Declarators ?
77  SymbolLookup::TemplateParameterScope *my_template_parameters;
78};
79
80}
81
82#endif