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
|
#include "stdafx.h"
#include "CompilerProtocol.h"
#include "Core/Io/Url.h"
namespace storm {
CompilerProtocol::CompilerProtocol() : libName(null) {}
CompilerProtocol::CompilerProtocol(Str *libName) : libName(libName) {}
Bool CompilerProtocol::partEq(Str *a, Str *b) {
return *a == *b;
}
Nat CompilerProtocol::partHash(Str *a) {
return a->hash();
}
Str *CompilerProtocol::format(Url *url) {
#ifdef DEBUG
StrBuf *to = new (this) StrBuf();
#ifdef WINDOWS
const wchar *sep = S("\\");
#else
const wchar *sep = S("/");
#endif
Url *root = dbgRootUrl(engine());
if (libName)
root = *root / libName;
*to << root->format();
Array<Str *> *parts = url->getParts();
for (Nat i = 0; i < parts->count(); i++) {
*to << sep << parts->at(i);
}
return to->toS();
#else
throw new (this) ProtocolNotSupported(S("format"), toS());
#endif
}
void CompilerProtocol::toS(StrBuf *to) const {
#ifdef DEBUG
Url *root = dbgRootUrl(engine());
if (libName)
root = root->pushDir(libName);
*to << root;
#else
*to << S("source for ");
if (libName)
*to << libName;
else
*to << S("compiler");
*to << S(":");
#endif
}
Bool CompilerProtocol::isEqualTo(const Protocol *o) const {
const CompilerProtocol *other = as<const CompilerProtocol>(o);
if (!other)
return false;
if (libName == other->libName)
return true;
if (libName == null || other->libName == null)
return false;
return *libName == *other->libName;
}
}
|