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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/* $Id$
*
* For different symbol bearing nodes, determine the full vhdl path name.
*
* Copyright (C) 2008-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.
*/
#include "frontend/visitor/SetPathName.hpp"
#include <cassert>
#include "frontend/visitor/ResolveTypes.hpp"
#include "frontend/ast/Library.hpp"
#include "frontend/ast/Entity.hpp"
#include "frontend/ast/Architecture.hpp"
#include "frontend/ast/Package.hpp"
#include "frontend/ast/Process.hpp"
#include "frontend/ast/FunctionDeclaration.hpp"
#include "frontend/ast/ProcedureDeclaration.hpp"
#include "util/MiscUtil.hpp"
namespace ast {
SetPathName::SetPathName() : anonCounter(0)
{
}
void
SetPathName::visit(Library &node)
{
this->currentPath.push_back(*node.name);
this->listTraverse(node.units);
this->currentPath.pop_back();
}
void
SetPathName::visit(Entity &node)
{
//FIXME? LRM, p202 doesn't show the library path name?
this->currentPath.push_back(*node.name);
if (node.generics != NULL) {
this->listTraverse(*node.generics);
}
if (node.ports != NULL) {
this->listTraverse(*node.ports);
}
if (node.declarations != NULL) {
this->listTraverse(*node.declarations);
}
this->currentPath.pop_back();
this->process(node);
}
void
SetPathName::visit(Architecture &node)
{
assert(node.entity != NULL);
this->currentPath.push_back(*node.entity->name);
//skip use and library clauses
if (node.declarations != NULL) {
this->listTraverse(*node.declarations);
}
//FIXME two architectures for same entity not handled.
this->anonCounter = 0;
if (node.concurrentStats != NULL) {
this->listTraverse(*node.concurrentStats);
}
this->currentPath.pop_back();
this->process(node);
}
void
SetPathName::visit(Package &node)
{
assert(node.name != NULL);
this->currentPath.push_back(*node.name);
TopDownVisitor::visit(node);
this->currentPath.pop_back();
this->process(node);
}
void
SetPathName::visit(Process &node)
{
if (node.name != NULL) {
this->process(node);
this->currentPath.push_back(*node.name);
} else {
std::string anonName = "__anonymous__"
+ util::MiscUtil::toString(this->anonCounter);
this->anonCounter++;
this->currentPath.push_back(anonName);
node.pathName = this->getPath();
}
if (node.declarations != NULL) {
this->listTraverse(*node.declarations);
}
if (node.seqStats != NULL) {
this->listTraverse(*node.seqStats);
}
this->currentPath.pop_back();
}
void
SetPathName::visit(FunctionDeclaration &node)
{
assert(node.returnType != NULL);
const TypeDeclaration *returnType =
ResolveTypes::findBaseType(node.returnType);
assert(returnType != NULL);
std::string suffix = "return " + *(returnType->name);
this->processCallable(node, &suffix);
}
void
SetPathName::visit(ProcedureDeclaration &node)
{
this->processCallable(node, NULL);
}
void
SetPathName::process(SymbolDeclaration &node)
{
if (node.name != NULL) {
node.pathName = this->getPath() + *node.name + ':';
}
}
void
SetPathName::processCallable(Callable &node, const std::string *pSuffix)
{
std::string argPathName = *node.name;
assert(node.arguments != NULL);
argPathName += "[";
for (std::list<ValDeclaration*>::const_iterator i =
node.arguments->begin(); i != node.arguments->end(); i++) {
if (i != node.arguments->begin()) {
argPathName += ",";
}
const TypeDeclaration *baseType =
ResolveTypes::findBaseType((*i)->subtypeIndic);
argPathName += *baseType->name;
}
if (! (node.arguments->empty() || (pSuffix == NULL))) {
argPathName += ' ';
}
if (pSuffix != NULL) {
argPathName += (*pSuffix);
}
argPathName += "]";
this->currentPath.push_back(argPathName);
node.pathName = this->getPath();
this->listTraverse(*node.arguments);
if (node.definition != NULL) {
node.definition->accept(*this);
}
this->currentPath.pop_back();
}
std::string
SetPathName::getPath(void) const
{
std::string ret;
for (std::list<std::string>::const_iterator i =
this->currentPath.begin(); i != this->currentPath.end();
i++) {
ret += ":";
ret += *i;
}
ret += ":";
return ret;
}
}; /* namespace ast */
|