StringConstant.cpp 2.14 KB
Newer Older
gsell's avatar
gsell committed
1
//
2 3
// Class StringConstant
//   The STRING CONSTANT definition.
gsell's avatar
gsell committed
4
//
5 6
// Copyright (c) 2000 - 2021, Paul Scherrer Institut, Villigen PSI, Switzerland
// All rights reserved
gsell's avatar
gsell committed
7
//
8 9 10 11 12 13 14 15 16
// This file is part of OPAL.
//
// OPAL is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// You should have received a copy of the GNU General Public License
// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
gsell's avatar
gsell committed
17 18
//
#include "ValueDefinitions/StringConstant.h"
19

kraus's avatar
kraus committed
20
#include "AbstractObjects/OpalData.h"
gsell's avatar
gsell committed
21
#include "Attributes/Attributes.h"
22
#include "Utilities/Util.h"
gsell's avatar
gsell committed
23

24
#include <iostream>
gsell's avatar
gsell committed
25 26 27 28 29 30 31 32


StringConstant::StringConstant():
    ValueDefinition(1, "STRING_CONSTANT",
                    "The \"STRING CONSTANT\" statement defines a global "
                    "string constant:\n"
                    "\tSTRING CONSTANT <name> = <String-expression>;\n") {
    itsAttr[0] = Attributes::makeString("VALUE", "The constant value");
kraus's avatar
kraus committed
33

34 35
    registerOwnership(AttributeHandler::STATEMENT);

36
    OpalData *opal = OpalData::getInstance();
37
    opal->create(new StringConstant("GITREVISION", this, Util::getGitRevision()));
gsell's avatar
gsell committed
38 39 40
}


41
StringConstant::StringConstant(const std::string &name, StringConstant *parent):
gsell's avatar
gsell committed
42 43 44 45
    ValueDefinition(name, parent)
{}


kraus's avatar
kraus committed
46 47 48 49 50 51 52 53 54
StringConstant::StringConstant(const std::string &name, StringConstant *parent, const std::string &value):
    ValueDefinition(name, parent)
{
    Attributes::setString(itsAttr[0], value);
    itsAttr[0].setReadOnly(true);
    builtin = true;
}


gsell's avatar
gsell committed
55 56 57 58 59 60 61 62 63
StringConstant::~StringConstant()
{}


bool StringConstant::canReplaceBy(Object *) {
    return false;
}


64
StringConstant *StringConstant::clone(const std::string &name) {
gsell's avatar
gsell committed
65 66 67 68
    return new StringConstant(name, this);
}


69
std::string StringConstant::getString() const {
gsell's avatar
gsell committed
70 71 72 73 74 75 76
    return Attributes::getString(itsAttr[0]);
}


void StringConstant::print(std::ostream &os) const {
    os << "STRING " << getOpalName() << '=' << itsAttr[0] << ';';
    os << std::endl;
77 78 79 80
}

void StringConstant::printValue(std::ostream &os) const {
    os << itsAttr[0];
81
}