summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d169879)
raw | patch | inline | side by side (parent: d169879)
author | Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl> | |
Tue, 9 Aug 2011 16:04:19 +0000 (17:04 +0100) | ||
committer | Gert van Valkenhoef <g.h.m.van.valkenhoef@rug.nl> | |
Tue, 9 Aug 2011 16:04:19 +0000 (17:04 +0100) |
alien.cc | patch | blob | history | |
alien.h | patch | blob | history | |
reader.cc | patch | blob | history | |
reader.h | patch | blob | history | |
store.cc | patch | blob | history | |
store.h | patch | blob | history |
diff --git a/alien.cc b/alien.cc
index 7a225b71932e33b20e570e04de81712f12849623..d82a33ca1a2f120a008e9561e197ad644018fd8a 100644 (file)
--- a/alien.cc
+++ b/alien.cc
return store->toString();
}
-Alien::Alien(INTEGER id, SHORTCHAR **path): Store(id), d_path(path), d_comps() {}
+Alien::Alien(INTEGER id, const TypePath &path): Store(id), d_path(path), d_comps() {}
std::vector<AlienComponent*> & Alien::getComponents() {
return d_comps;
}
std::string Alien::toString() {
- std::string sofar = std::string(d_path[0]) + "{ ";
+ std::string sofar = d_path.toString() + "{ ";
for (int i = 0; i < d_comps.size(); ++i) {
sofar += d_comps[i]->toString() + " ";
}
index 40ef09ab838b9c21b5860549acfddedd9e680b3a..0c4b51dd4e810eb0c52b175a26469cb0e146c999 100644 (file)
--- a/alien.h
+++ b/alien.h
#include <store.h>
#include <iostream>
#include <vector>
+#include <string>
namespace odc {
};
class Alien : public Store {
- SHORTCHAR **d_path;
+ const TypePath d_path;
std::vector<AlienComponent*> d_comps;
public:
- Alien(INTEGER id, SHORTCHAR **path);
+ Alien(INTEGER id, const TypePath &path);
std::vector<AlienComponent*> & getComponents();
diff --git a/reader.cc b/reader.cc
index 051ddf555539dbc7440b12694dbe4f2ad7f62383..08bd498f174bbe7167562eff91fb8cd7fae2bd4d 100644 (file)
--- a/reader.cc
+++ b/reader.cc
Store *Reader::readStoreOrElemStore(bool isElem) {
INTEGER id = isElem ? d_elemList.size() : d_storeList.size();
- SHORTCHAR** path = newTypePath();
- readPath(path);
- for (int i = 0; path[i] != 0; ++i) {
- std::cout << path[i] << std::endl;
- }
- SHORTCHAR* type = path[0];
+ TypePath path = readPath();
+ std::cout << path.toString() << std::endl;
+ const std::string &type = path[0];
INTEGER comment = readInt();
std::streampos pos1 = d_rider.tellg();
std::streamoff next = readInt();
@@ -237,18 +234,22 @@ void Reader::internalizeAlien(Alien *alien, std::streampos down, std::streampos
}
}
-void Reader::readPath(SHORTCHAR **path) {
+TypePath Reader::readPath() {
+ TypePath path;
SHORTCHAR kind = readSChar();
+ SHORTCHAR *buf = new SHORTCHAR[64]; // TypeName has a maximum of length 64 (including terminator).
int i;
for (i = 0; kind == Store::NEWEXT; ++i) {
- readSString(path[i]);
+ readSString(buf);
+ path.push_back(std::string(buf));
addPathComponent(i == 0, path[i]);
// IF path[i] # elemTName THEN INC(i) END;
kind = readSChar();
}
if (kind == Store::NEWBASE) {
- readSString(path[i]);
+ readSString(buf);
+ path.push_back(std::string(buf));
addPathComponent(i == 0, path[i]);
++i;
} else if (kind == Store::OLDTYPE) {
d_typeList[d_typeList.size() - 1]->baseId = id;
}
while (id != -1) {
- path[i] = d_typeList[id]->name;
+ path.push_back(d_typeList[id]->name);
id = d_typeList[id]->baseId;
// IF path[i] # elemTName THEN INC(i) END
++i;
} else {
throw 100;
}
- path[i] = 0;
+ return path;
}
-void Reader::addPathComponent(bool first, SHORTCHAR *typeName) {
+void Reader::addPathComponent(bool first, const std::string &typeName) {
int next = d_typeList.size();
int curr = next - 1;
if (!first) {
diff --git a/reader.h b/reader.h
index 208cf287a34875be20020ec159fe3fb44fb009fb..764a27618138fa5d4d7f098b04510fff6151964a 100644 (file)
--- a/reader.h
+++ b/reader.h
namespace odc {
-class TypeEntry {
- public:
- SHORTCHAR *name;
+struct TypeEntry {
+ const std::string name;
INTEGER baseId;
- TypeEntry(SHORTCHAR *typeName) : name(typeName), baseId(-1) {}
+ TypeEntry(const std::string &typeName) : name(typeName), baseId(-1) {}
};
/**
Store *readNewLinkStore();
void internalizeAlien(Alien *alien, std::streampos down, std::streampos end);
- /*
- TypeName* = ARRAY 64 OF CHAR;
- TypePath* = ARRAY 16 OF TypeName;
- OpName* = ARRAY 32 OF CHAR;
- */
- inline SHORTCHAR *newTypeName() {
- return new SHORTCHAR[64];
- }
- inline SHORTCHAR **newTypePath() {
- SHORTCHAR **out = new SHORTCHAR*[16];
- for (int i = 0; i < 16; ++i) {
- out[i] = newTypeName();
- }
- return out;
- }
- void readPath(SHORTCHAR **path);
+ TypePath readPath();
/**
* Add another component to the current path. If first==true, start a new path.
*/
- void addPathComponent(bool first, SHORTCHAR *typeName);
+ void addPathComponent(bool first, const std::string &typeName);
};
} // namespace odc
diff --git a/store.cc b/store.cc
index d7db23be164b68e41a7da87834f50e951aed801f..82e20e67c7c1e0dac7cb4a1358706e811057af19 100644 (file)
--- a/store.cc
+++ b/store.cc
namespace odc {
+template<class T, class A> T join(const A & begin, const A & end, const T &sep) {
+ T result;
+
+ if (begin != end) {
+ A it = begin;
+ result.append(*it);
+ for (++it; it != end; ++it) {
+ result.append(sep).append(*it);
+ }
+ }
+
+ return result;
+}
+
+std::string TypePath::toString() const {
+ return join(begin(), end(), std::string("->"));
+}
+
Store::Store(INTEGER id): d_id(id) {}
INTEGER Store::getId() {
index be351b70ea70092709155aa9b1c2e750d95e7ceb..039354d5b5c120737498795f9267a65babea13ca 100644 (file)
--- a/store.h
+++ b/store.h
#include <domain.h>
#include <string>
+#include <vector>
namespace odc {
+ class TypePath : public std::vector<std::string> {
+ public:
+ std::string toString() const;
+ };
+
/**
* TYPE Store
* ABSTRACT