Synopsis - Cross-Reference

File: /sandbox/bpl/SymbolLookup.cc
 1//
 2// Copyright (C) 2005 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#include <Synopsis/SymbolLookup.hh>
 8#include <boost/python.hpp>
 9
10namespace bpl = boost::python;
11using namespace Synopsis;
12using namespace Synopsis::SymbolLookup;
13
14namespace
15{
16
17SymbolSet lookup_symbol(Scope const *scope, PTree::Encoding const &enc)
18{
19  return scope->lookup(enc);
20}
21
22}
23
24BOOST_PYTHON_MODULE(SymbolLookup)
25{
26  bpl::class_<SymbolSet> symbol_set("SymbolSet");
27
28  bpl::class_<Scope, Scope *, boost::noncopyable> scope("Scope", bpl::no_init);
29  scope.def("outer_scope", &Scope::outer_scope, bpl::return_value_policy<bpl::reference_existing_object>());
30  scope.def("global_scope", &Scope::global_scope, bpl::return_value_policy<bpl::reference_existing_object>());
31  scope.def("lookup", lookup_symbol);
32
33  bpl::class_<Symbol, Symbol *, boost::noncopyable> symbol("Symbol", bpl::no_init);
34  symbol.add_property("type",
35		      bpl::make_function(&Symbol::type,
36					 bpl::return_internal_reference<>()));
37  // FIXME: find appropriate return value policy
38  symbol.add_property("scope",
39		      bpl::make_function(&Symbol::scope,
40					 bpl::return_value_policy<bpl::reference_existing_object>()));
41  // FIXME: should probably rename Symbol::ptree to Symbol::declarator, too
42  symbol.add_property("declarator",
43		      bpl::make_function(&Symbol::ptree,
44					 bpl::return_value_policy<bpl::reference_existing_object>()));
45
46  // symbols
47
48  bpl::class_<VariableName, bpl::bases<Symbol>, VariableName *,
49              boost::noncopyable> variable_name("VariableName", bpl::no_init);
50
51  bpl::class_<ConstName, bpl::bases<Symbol>, ConstName *,
52              boost::noncopyable> const_name("ConstName", bpl::no_init);
53  // FIXME: should probably rename ConstName::defined to ConstName::is_defined, too
54  const_name.def("is_defined", &ConstName::defined);
55  const_name.add_property("value", &ConstName::value);
56
57  bpl::class_<TypeName, bpl::bases<Symbol>, TypeName *,
58              boost::noncopyable> type_name("TypeName", bpl::no_init);
59
60  bpl::class_<TypedefName, bpl::bases<TypeName>, TypedefName *,
61              boost::noncopyable> typedef_name("TypedefName", bpl::no_init);
62
63  bpl::class_<ClassTemplateName, bpl::bases<Symbol>, ClassTemplateName *,
64              boost::noncopyable> class_tmpl_name("ClassTemplateName", bpl::no_init);
65
66  bpl::class_<FunctionName, bpl::bases<Symbol>, FunctionName *,
67              boost::noncopyable> function_name("FunctionName", bpl::no_init);
68
69  bpl::class_<FunctionTemplateName, bpl::bases<Symbol>, FunctionTemplateName *,
70              boost::noncopyable> function_tmpl_name("FunctionTemplateName", bpl::no_init);
71
72  bpl::class_<NamespaceName, bpl::bases<Symbol>, NamespaceName *,
73              boost::noncopyable> namespace_name("NamespaceName", bpl::no_init);
74
75  // scopes
76
77  bpl::class_<TemplateParameterScope, bpl::bases<Scope>, TemplateParameterScope *,
78              boost::noncopyable> template_parameter_scope("TemplateParameterScope", bpl::no_init);
79
80  bpl::class_<LocalScope, bpl::bases<Scope>, LocalScope *,
81              boost::noncopyable> local_scope("LocalScope", bpl::no_init);
82
83  bpl::class_<FunctionScope, bpl::bases<Scope>, FunctionScope *,
84              boost::noncopyable> function_scope("FunctionScope", bpl::no_init);
85
86  bpl::class_<PrototypeScope, bpl::bases<Scope>, PrototypeScope *,
87              boost::noncopyable> prototype_scope("PrototypeScope", bpl::no_init);
88
89  bpl::class_<Class, bpl::bases<Scope>, Class *,
90              boost::noncopyable> class_("Class", bpl::no_init);
91
92  bpl::class_<Namespace, bpl::bases<Scope>, Namespace *,
93              boost::noncopyable> namespace_("Namespace", bpl::no_init);
94
95}