Synopsis - Cross-Reference

File: /Synopsis/Parsers/Cxx/Dictionary.hh
  1//
  2// Copyright (C) 2001 Stephen Davies
  3// Copyright (C) 2001 Stefan Seefeld
  4// All rights reserved.
  5// Licensed to the public under the terms of the GNU LGPL (>= 2),
  6// see the file COPYING for details.
  7//
  8
  9#ifndef Dictionary_hh_
 10#define Dictionary_hh_
 11
 12#include <vector>
 13#include <string>
 14#include "common.hh"
 15#include "FakeGC.hh"
 16
 17// Forward declaration of Type::Named
 18namespace Types
 19{
 20class Named;
 21}
 22
 23// Forward declaration of ASG::Declaration
 24namespace ASG
 25{
 26class Declaration;
 27}
 28
 29//. Dictionary of named declarations with lookup.
 30//. This class maintains a dictionary of names, which index types,
 31//. supposedly declared in the scope that has this dictionary. There may be
 32//. only one declaration per name, except in the case of function names.
 33class Dictionary : public FakeGC::LightObject
 34{
 35public:
 36    //. Constructor
 37    Dictionary();
 38    //. Destructor
 39    ~Dictionary();
 40
 41    //. The type of multiple entries. We don't want to include type.hh just for
 42    //. this, so this is a workaround
 43    typedef std::vector<Types::Named*> Type_vector;
 44
 45    //. Exception thrown when multiple declarations are found when one is
 46    //. expected. The list of declarations is stored in the exception.
 47    struct MultipleError
 48    {
 49        MultipleError(const std::string& n) : name(n) {}
 50        // The vector of types that *were* found. This is returned so that whoever
 51        // catches the error can proceed straight away
 52        std::string name;
 53        Type_vector types;
 54    };
 55
 56    //. Exception thrown when a name is not found in lookup*()
 57    struct KeyError
 58    {
 59        //. Constructor
 60        KeyError(const std::string& n)
 61                : name(n)
 62        { }
 63        //. The name which was not found
 64        std::string name;
 65    };
 66
 67    //. Returns true if name is in dict
 68    bool has_key(const std::string& name);
 69
 70    //. Lookup a name in the dictionary. If more than one declaration has this
 71    //. name then an exception is thrown.
 72    Types::Named* lookup(const std::string& name);// throw (MultipleError, KeyError);
 73
 74    //. Lookup a name in the dictionary expecting multiple decls. Use this
 75    //. method if you expect to find more than one declaration, eg importing
 76    //. names via a using statement.
 77    Type_vector lookupMultiple(const std::string& name) throw (KeyError);
 78
 79    //. Add a declaration to the dictionary. The name() is extracted from the
 80    //. declaration and its last string used as the key. The declaration is
 81    //. stored as a Type::Declared which is created inside this method.
 82    void insert(ASG::Declaration* decl);
 83
 84    //. Add a named type to the dictionary. The name() is extracted from the
 85    //. type and its last string used as they key.
 86    void insert(Types::Named* named);
 87
 88    //. Dump the contents for debugging
 89    void dump();
 90
 91
 92private:
 93    struct Data;
 94    //. The private data. This is a forward declared * to speed compilation since
 95    //. std::map is a large template.
 96    Data*  m;
 97};
 98
 99#endif // header guard
100// vim: set ts=8 sts=4 sw=4 et: