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
|
#include "If.h"
#include "CompileState.h"
#include "Expression.h"
#include "FileStructure.h"
#include "Sequence.h"
#include <iostream>
If::Control::~Control()
{
}
If::IfDef::IfDef(const std::string& aName)
: Macro(aName)
{
}
If::IfDef::IfDef(const If::IfDef& anOther)
: Macro(anOther.Macro)
{
}
If::IfDef::~IfDef()
{
}
If::Control* If::IfDef::copy() const
{
return new If::IfDef(*this);
}
bool If::IfDef::isTrue(CompileState* aState) const
{
return aState->isDefined(Macro);
}
If::IfNDef::IfNDef(const std::string& aName)
: Macro(aName)
{
}
If::IfNDef::IfNDef(const If::IfNDef& anOther)
: Macro(anOther.Macro)
{
}
If::IfNDef::~IfNDef()
{
}
If::Control* If::IfNDef::copy() const
{
return new If::IfNDef(*this);
}
bool If::IfNDef::isTrue(CompileState* aState) const
{
return !aState->isDefined(Macro);
}
If::IfTest::IfTest(const std::string& anExpression)
: theExpression(anExpression)
{
}
If::IfTest::IfTest(const If::IfTest& anOther)
: theExpression(anOther.theExpression)
{
}
If::Control* If::IfTest::copy() const
{
return new If::IfTest(*this);
}
bool If::IfTest::isTrue(CompileState* aState) const
{
Expression E(theExpression, aState);
return E.evaluate();
}
If::If(FileStructure* aStructure)
: Element(aStructure), Else(0)
{
}
If::If(const If& anOther)
: Element(anOther), Else(0)
{
for (unsigned int i=0; i<anOther.Expr.size(); ++i)
Expr.push_back(anOther.Expr[i]->copy());
for (unsigned int j=0; j<anOther.Seq.size(); ++j)
Seq.push_back(dynamic_cast<Sequence*>(anOther.Seq[j]->copy()));
if (anOther.Else)
Else = dynamic_cast<Sequence*>(anOther.Else->copy());
}
If::~If()
{
for (unsigned int i=0; i<Expr.size(); ++i)
delete Expr[i];
}
If& If::operator=(const If& anOther)
{
if (this != &anOther)
{
Element::operator=(*this);
Expr.erase(Expr.begin(), Expr.end());
for (unsigned int i=0; i<anOther.Expr.size(); ++i)
Expr.push_back(anOther.Expr[i]->copy());
for (unsigned int j=0; j<anOther.Seq.size(); ++j)
Seq.push_back(dynamic_cast<Sequence*>(anOther.Seq[j]->copy()));
if (Else)
{
delete Else;
Else = 0;
}
if (anOther.Else)
Else = dynamic_cast<Sequence*>(anOther.Else->copy());
}
return *this;
}
Element* If::copy() const
{
return new If(*this);
}
void If::getDependencies(CompileState* aState)
{
for (unsigned int i=0; i<Expr.size(); ++i)
if (Expr[i]->isTrue(aState))
{
// std::cout << "following in if part " << i << std::endl;
Seq[i]->getDependencies(aState);
return;
}
// std::cout << "skipping to ...";
if (Else)
{
// std::cout << "else" << std::endl;
Else->getDependencies(aState);
}
// else
// std::cout << "nothing" << std::endl;
}
Sequence* If::addIf(Control* anExpr)
{
Expr.push_back(anExpr);
Seq.push_back(new Sequence(getStructure()));
return Seq[Seq.size()-1];
}
Sequence* If::addElse()
{
if (!Else)
Else = new Sequence(getStructure());
return Else;
}
Sequence* If::getLastScope()
{
if (Else)
return Else;
return Seq[Seq.size()-1];
}
|