1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
|
/* $Id$
*
* DeclarativeRegion: One pocket to store symbols. Can be chained together.
*
* Copyright (C) 2007-2009 FAUmachine Team <info@faumachine.org>.
* This program is free software. You can redistribute it and/or modify it
* under the terms of the GNU General Public License, either version 2 of
* the License, or (at your option) any later version. See COPYING.
*/
#ifndef __DECLARATIVE_REGION_HPP_INCLUDED
#define __DECLARATIVE_REGION_HPP_INCLUDED
#include <list>
#include <string>
#include "frontend/misc/Symbol.hpp"
namespace ast {
//! one declarative region
class DeclarativeRegion {
public:
//! c'tor
/**
* @param p link to parent declarative region, NULL in case
* it's a library declarative region.
*/
DeclarativeRegion(DeclarativeRegion *p);
/** d'tor */
~DeclarativeRegion();
/** register symbol sym to declarations.
* @param sym Symbol that should get registered.
*/
void registerSymbol(Symbol *sym);
/** lookup name symbol by name.
* @param name search for this name.
* @return visible candidates for given symbol.
*/
std::list<Symbol*> lookup(const std::string &name) const ;
/** check if sym is the symbol of an enclosing region
* @param sym symbol to check.
* @return true, if sym declares a region which encloses
* this region.
*/
bool isEnclosingSymbol(const Symbol &sym) const;
/** symbols declared in this region */
std::list<Symbol*> declarations;
/** symbols visible through use-clauses */
std::list<Symbol*> imports;
/** parent declarative region */
DeclarativeRegion *parent;
// FIXME potyra: use a better storage facility than just an
// unordered list. Maybe a hashtable or s.th. like that.
/** lookup name symbol by name, only in current DeclarativeRegion,
* not considering imported symbols.
* @param name search for this name
* @return candidates for given symbol of local region.
*/
std::list<Symbol*> lookupLocal(const std::string &name) const;
private:
/** check if this region contains a Homograph to
* symbol sym already.
* @param sym check for a Homograph of this symbol.
* @return the Symbol, which is a Homograph or NULL if
* no Homograph exists.
*/
const Symbol* containsHomograph(const Symbol &sym) const;
/** recursively search (parent) declarative regions
* that resolve the symbol with name.
* @param name name to look for.
* @param candidates list of Symbols which are candidates to
* resolve given name.
*/
void
lookupRec(
const std::string &name,
std::list<Symbol*> &candidates
) const;
/** check if symbol sym is visible in the context of a set of
* possible homographs.
* @param sym contains the symbol for which visibility should get
* checked.
* @param check list of symbols, which possibly hide sym.
* @return true if the symbol is visible.
*/
bool
isVisible(
const Symbol &sym,
const std::list<Symbol*> &check
) const;
};
}; /* namespace ast */
#endif /* __DECLARATIVE_REGION_HPP_INCLUDED */
|