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
|
/* $Id$
*
* SimplifyExpressions: simplify nested expressions to simple expressions.
*
* Copyright (C) 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/SimplifyExpressions.hpp"
#include "frontend/ast/Process.hpp"
#include "frontend/ast/VarAssignStat.hpp"
#include "frontend/ast/FunctionCall.hpp"
namespace ast {
void
SimplifyExpressions::visit(Process &node)
{
this->simpleSeqs.clear();
assert(node.seqStats != NULL);
this->listTraverse(*node.seqStats, this->simpleSeqs);
/* TODO: pickup new declarations.
node.declarations->push_back(FIXME);
*/
}
void
SimplifyExpressions::visit(VarAssignStat &node)
{
assert(node.source != NULL);
assert(node.target != NULL);
node.source->accept(*this);
this->setNode(node.source);
}
void
SimplifyExpressions::visit(SigAssignStat &node)
{
// FIXME
}
void
SimplifyExpressions::visit(CondalSigAssign &node)
{
// must have been replaced already.
assert(false);
}
void
SimplifyExpressions::visit(FunctionCall &node)
{
// TODO
}
void
SimplifyExpressions::setNode(Expression *&e)
{
if (this->repexp != NULL) {
e = this->repexp;
this->repexp = NULL;
}
}
SimpleName *
SimplifyExpressions::genTemporary(
SubtypeIndication *type,
std::string name,
const char *suffix
)
{
if (name == "") {
name = "tmp";
}
if (suffix == NULL) {
suffix = "";
}
name = "__" + name + suffix;
std::string *namep = new std::string(name);
VarDeclaration *vd =
new VarDeclaration(
ValDeclaration::MODE_INOUT,
namep,
NULL,
type,
Location("simplified"));
std::list<Symbol*> cands = std::list<Symbol*>();
Symbol *sym = new Symbol(namep, SYMBOL_VARIABLE, NULL, *vd);
cands.push_back(sym);
SimpleName *ret = new SimpleName(
new std::string(name),
cands,
Location("simplified"));
return ret;
}
} /* namespace ast */
|