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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
|
/* $Id$
*
* Symbol: A symbol refers to a named entity.
*
* 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 __SYMBOL_HPP_INCLUDED
#define __SYMBOL_HPP_INCLUDED
#include <string>
#include <ostream>
#include "frontend/ast/SymbolDeclaration.hpp"
#include "frontend/ast/SubtypeIndication.hpp"
namespace ast {
/** type of the symbol */
enum symType {
/** symbol is an Entity */
SYMBOL_ENTITY = 1 << 0,
/** symbol is a procedure declaration */
SYMBOL_PROCEDURE = 1 << 1,
/** symbol is a function declaration */
SYMBOL_FUNCTION = 1 << 2,
/** symbol is a signal declaration */
SYMBOL_SIGNAL = 1 << 3,
/** symbol is a variable or constant declaration */
SYMBOL_VARIABLE = 1 << 4,
/** symbol is a type declaration */
SYMBOL_TYPE = 1 << 5,
/** symbol is a unit of a physical unit */
SYMBOL_UNIT = 1 << 6,
/** symbol is an element of a record type */
SYMBOL_ELEMENT = 1 << 7,
/** symbol is an attribute declaration */
SYMBOL_ATTRIBUTE = 1 << 8,
/** symbol is an Architecture */
SYMBOL_ARCHITECTURE = 1 << 9,
/** symbol is a Process */
SYMBOL_PROCESS = 1 << 10,
/** symbol is a Loop label */
SYMBOL_LOOP = 1 << 11,
/** symbol denotes a library */
SYMBOL_LIBRARY = 1 << 12,
/** symbol denotes a package */
SYMBOL_PACKAGE = 1 << 13,
/** pseudo symbol denoting "all" token */
SYMBOL_ALL = 1 << 14,
/** symbol is a paramter */
SYMBOL_PARAMETER = 1 << 15,
/** symbol is a port */
SYMBOL_PORT = 1 << 16
};
// forward declaration of DeclarativeRegion
class DeclarativeRegion;
//! symbol entry in the SymbolTable.
/** The class Symbol represents one entry in the SymbolTable.
* TODO path of symbol
*/
class Symbol {
public:
//! c'tor
/** @param sname name of the Symbol
* @param stype type of the Symbol.
* @param decl reference to declaration.
* @param reg DeclarativeRegion the Symbol belongs to.
*/
Symbol(
const std::string* sname,
enum symType stype,
DeclarativeRegion* reg,
SymbolDeclaration& decl
) : name(sname),
type(stype),
declaration(decl),
region(reg) {}
//! d'tor
~Symbol() {
SymbolDeclaration* decl = &(this->declaration);
util::MiscUtil::terminate(decl);
}
/** check if other is a Homograph of this. */
bool isHomograph(const Symbol& other) const;
/** name of the symbol */
const std::string* name;
/** type of the symbol */
enum symType type;
/** referring declaration of the Symbol. */
SymbolDeclaration &declaration;
/** possibly asssociated DeclarativeRegion of the symbol,
* NULL possible. */
DeclarativeRegion *region;
/** write the Symbol to stream.
* @param stream write the symbol to this stream
*/
void put(std::ostream& stream) const;
private:
/** does the other symbol, which points to a callable have the
* same parameter type profile (LRM 2.3)?
*
* @param other other symbol that points to a Callable.
* @return true, if the other symbol has the same parameter type
* profile, false otherwise.
*/
bool sameParameterProfile(const Symbol& other) const;
/** does the other symbol, which points to a FunctionDeclaration
* as well as this have the same result type profile?
*
* @param other other symbol that points to a FunctionDeclaration.
* @return true if the result profile match, false otherwise.
*/
bool sameResultProfile(const Symbol& other) const;
/** are the base types of given SubtypeIndication's equal?
* Note: both SubtypeIndications need to have been resolved already.
*
* @param s1 first SubtypeIndication.
* @param s2 second SubtypeIndication.
* @return true if the base types are identical, false otherwise.
*/
static bool baseTypeEqual(
const SubtypeIndication& s1,
const SubtypeIndication& s2
);
};
/** write a symbol to a stream.
* @param stream stream to which the symbol should get written to.
* @param sym symbol that should get written.
* @return modified stream.
*/
std::ostream& operator<<(std::ostream& stream, const Symbol& sym);
}; /* namespace ast */
#endif /* __SYMBOL_HPP_INCLUDED */
|