Commit ee231a93 authored by snuverink_j's avatar snuverink_j
Browse files

Merge branch '480-value-command-does-not-print-variable-names' into 'master'

Resolve "`VALUE` command does not print variable names"

Closes #480

See merge request !295
parents 57c8ae00 68f88ece
......@@ -28,10 +28,7 @@
#include "Utilities/Round.h"
#include <iostream>
//using std::cerr;
//using std::endl;
using std::vector;
using namespace std;
#include <vector>
extern Inform *gmsg;
......@@ -41,7 +38,7 @@ extern Inform *gmsg;
Object::~Object() {
// Invalidate all references to this object.
for(set<Invalidator *>::iterator i = references.begin();
for(std::set<Invalidator *>::iterator i = references.begin();
i != references.end(); ++i) {
(*i)->invalidate();
}
......@@ -64,8 +61,8 @@ void Object::execute() {
}
Attribute *Object::findAttribute(const string &name) {
for(vector<Attribute>::iterator i = itsAttr.begin();
Attribute *Object::findAttribute(const std::string &name) {
for(std::vector<Attribute>::iterator i = itsAttr.begin();
i != itsAttr.end(); ++i) {
if(i->getName() == name) return &(*i);
}
......@@ -74,8 +71,8 @@ Attribute *Object::findAttribute(const string &name) {
}
const Attribute *Object::findAttribute(const string &name) const {
for(vector<Attribute>::const_iterator i = itsAttr.begin();
const Attribute *Object::findAttribute(const std::string &name) const {
for(std::vector<Attribute>::const_iterator i = itsAttr.begin();
i != itsAttr.end(); ++i) {
if(i->getName() == name) return &(*i);
}
......@@ -85,13 +82,13 @@ const Attribute *Object::findAttribute(const string &name) const {
Object *Object::makeTemplate
(const string &name, TokenStream &, Statement &) {
(const std::string &name, TokenStream &, Statement &) {
throw ParseError("Object::makeTemplate()", "Object \"" + name +
"\" cannot be used to define a macro.");
}
Object *Object::makeInstance(const string &/*name*/, Statement &, const Parser *) {
Object *Object::makeInstance(const std::string &/*name*/, Statement &, const Parser *) {
throw ParseError("Object::makeInstance()", "Object \"" + getOpalName() +
"\" cannot be called as a macro.");
}
......@@ -99,7 +96,7 @@ Object *Object::makeInstance(const string &/*name*/, Statement &, const Parser *
void Object::parse(Statement &stat) {
while(stat.delimiter(',')) {
string name = Expressions::parseString(stat, "Attribute name expected.");
std::string name = Expressions::parseString(stat, "Attribute name expected.");
if(Attribute *attr = findAttribute(name)) {
if(stat.delimiter('[')) {
......@@ -129,19 +126,19 @@ void Object::parse(Statement &stat) {
}
void Object::parseShortcut(Statement &stat) {
void Object::parseShortcut(Statement &stat, bool eval) {
// Only one attribute.
if(stat.delimiter(',')) {
stat.mark();
string name;
std::string name;
if(stat.word(name)) {
if(stat.delimiter('=')) {
if(Attribute *attr = findAttribute(name)) {
attr->parse(stat, true);
attr->parse(stat, eval);
return;
} else {
throw ParseError("Object::parse()", "Object \"" + getOpalName() +
throw ParseError("Object::parseShortcut()", "Object \"" + getOpalName() +
"\" has no attribute \"" + name + "\".");
}
} else if(stat.delimiter(":=")) {
......@@ -149,7 +146,7 @@ void Object::parseShortcut(Statement &stat) {
attr->parse(stat, false);
return;
} else {
throw ParseError("Object::parse()", "Object \"" + getOpalName() +
throw ParseError("Object::parseShortcut()", "Object \"" + getOpalName() +
"\" has no attribute \"" + name + "\".");
}
}
......@@ -162,7 +159,7 @@ void Object::parseShortcut(Statement &stat) {
void Object::print(std::ostream & msg) const {
string head = getOpalName();
std::string head = getOpalName();
Object *parent = getParent();
if(parent != 0 && ! parent->getOpalName().empty()) {
if(! getOpalName().empty()) head += ':';
......@@ -172,12 +169,12 @@ void Object::print(std::ostream & msg) const {
msg << head;
int pos = head.length();
for(vector<Attribute>::const_iterator i = itsAttr.begin();
for(std::vector<Attribute>::const_iterator i = itsAttr.begin();
i != itsAttr.end(); ++i) {
if(*i) i->print(pos);
}
msg << ';';
msg << endl;
msg << std::endl;
return;
}
......@@ -208,17 +205,17 @@ void Object::printHelp(std::ostream &/*os*/) const {
*gmsg << "Attributes:" << endl;
size_t maxLength = 16;
vector<Attribute>::const_iterator it;
std::vector<Attribute>::const_iterator it;
for (it = itsAttr.begin(); it != itsAttr.end(); ++ it) {
string name = it->getName();
std::string name = it->getName();
maxLength = std::max(maxLength, name.length() + 1);
}
for (it = itsAttr.begin(); it != itsAttr.end(); ++ it) {
string type = it->getType();
string name = it->getName();
*gmsg << '\t' << type << string(16 - type.length(), ' ');
*gmsg << name << string(maxLength - name.length(), ' ');
std::string type = it->getType();
std::string name = it->getName();
*gmsg << '\t' << type << std::string(16 - type.length(), ' ');
*gmsg << name << std::string(maxLength - name.length(), ' ');
*gmsg << it->getHelp();
if(it->isReadOnly()) *gmsg << " (read only)";
*gmsg << endl;
......@@ -281,7 +278,7 @@ const Object *Object::getBaseObject() const {
}
const string &Object::getOpalName() const {
const std::string &Object::getOpalName() const {
return itsName;
}
......@@ -302,7 +299,7 @@ bool Object::isTreeMember(const Object *classObject) const {
}
void Object::setOpalName(const string &name) {
void Object::setOpalName(const std::string &name) {
itsName = name;
}
......@@ -339,7 +336,7 @@ Object::Object(int size, const char *name, const char *help):
}
Object::Object(const string &name, Object *parent):
Object::Object(const std::string &name, Object *parent):
RCObject(), itsAttr(parent->itsAttr), itsParent(parent),
itsName(name), itsHelp(parent->itsHelp), occurrence(0), sharedFlag(false) {
// The object is now different from the data base.
......
......@@ -111,7 +111,9 @@ public:
/// Parser for single-attribute commands.
// This parser allows to use unnamed attributes for command which
// have only one attribute.
virtual void parseShortcut(Statement &);
// If [b]eval[/b] is false, then the attribute is not evaluated immediately
// even if the delimiter is ``=''.
virtual void parseShortcut(Statement &, bool eval = true);
/// Print the object.
// Print a OPAL-readable image of [b]this[/b] on the given output stream.
......@@ -210,7 +212,7 @@ public:
void registerOwnership(const AttributeHandler::OwnerType &itsClass) const;
/// The object attributes (see Attribute.hh).
/// The object attributes.
std::vector<Attribute> itsAttr;
protected:
......
......@@ -17,9 +17,12 @@
// ------------------------------------------------------------------------
#include "BasicActions/Value.h"
#include "Attributes/Attributes.h"
#include <iomanip>
#include <iostream>
#include "Parser/Statement.h"
#include "Utility/Inform.h"
#include <string>
#include <vector>
......@@ -54,7 +57,7 @@ Value *Value::clone(const std::string &name) {
void Value::execute() {
*gmsg << "\nvalue: " << itsAttr[0] << "={";
*gmsg << "\nvalue: " << itsAttr[0] << " = {";
// std::streamsize old_prec = *gmsg.precision(12);
const std::vector<double> array = Attributes::getRealArray(itsAttr[0]);
std::vector<double>::const_iterator i = array.begin();
......@@ -62,14 +65,14 @@ void Value::execute() {
while(i != array.end()) {
*gmsg << *i++;
if(i == array.end()) break;
*gmsg << ",";
*gmsg << ", ";
}
*gmsg << "}\n" << endl;
// *gmsg.precision(old_prec);
}
void Value::parse(Statement &statement) {
parseShortcut(statement);
// parse, but don't evaluate (for printing mainly)
parseShortcut(statement, false);
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment