Fixed compilation with DMD 2.058.
There are some hacks to allow toHash() methods to be const nothrow @safe, these are due to Phobos problems (e.g. Variant.toHash() is not const nor nothrow).
This commit is contained in:
parent
c690d56d9f
commit
37a661b034
|
@ -550,7 +550,7 @@ ubyte[] constructBinary(ref Node node)
|
||||||
throw new Exception("Unable to decode base64 value: " ~ e.msg);
|
throw new Exception("Unable to decode base64 value: " ~ e.msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(UtfException e)
|
catch(UTFException e)
|
||||||
{
|
{
|
||||||
throw new Exception("Unable to decode base64 value: " ~ e.msg);
|
throw new Exception("Unable to decode base64 value: " ~ e.msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ class YAMLException : Exception
|
||||||
}
|
}
|
||||||
|
|
||||||
///Position in a YAML stream, used for error messages.
|
///Position in a YAML stream, used for error messages.
|
||||||
align(1) struct Mark
|
struct Mark
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
///Line number.
|
///Line number.
|
||||||
|
@ -49,6 +49,8 @@ align(1) struct Mark
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static assert(Mark.sizeof == 4, "Unexpected Mark size");
|
||||||
|
|
||||||
package:
|
package:
|
||||||
//Base class of YAML exceptions with marked positions of the problem.
|
//Base class of YAML exceptions with marked positions of the problem.
|
||||||
abstract class MarkedYAMLException : YAMLException
|
abstract class MarkedYAMLException : YAMLException
|
||||||
|
|
28
dyaml/node.d
28
dyaml/node.d
|
@ -200,6 +200,9 @@ struct Node
|
||||||
//Node collection style. Used to remember style this node was loaded with.
|
//Node collection style. Used to remember style this node was loaded with.
|
||||||
CollectionStyle collectionStyle = CollectionStyle.Invalid;
|
CollectionStyle collectionStyle = CollectionStyle.Invalid;
|
||||||
|
|
||||||
|
static assert(Value.sizeof <= 24, "Unexpected YAML value size");
|
||||||
|
static assert(Node.sizeof <= 48, "Unexpected YAML node size");
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Construct a Node from a value.
|
* Construct a Node from a value.
|
||||||
|
@ -1271,17 +1274,32 @@ struct Node
|
||||||
}
|
}
|
||||||
|
|
||||||
///Compare with another _node.
|
///Compare with another _node.
|
||||||
const int opCmp(ref const Node node)
|
int opCmp(ref const Node node) const
|
||||||
{
|
{
|
||||||
return cmp!true(node);
|
return cmp!true(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Compute hash of the node.
|
//Compute hash of the node.
|
||||||
const hash_t toHash()
|
hash_t toHash() const nothrow @safe
|
||||||
{
|
{
|
||||||
const tagHash = tag_.isNull ? 0 : tag_.toHash();
|
// Hack to allow const nothrow @safe.
|
||||||
//Variant toHash is not const at the moment, so we need to const-cast.
|
// Should be rewritten once std.variant is fixed.
|
||||||
return tagHash + (cast(Value)value_).toHash();
|
hash_t unsafeHash() nothrow @trusted
|
||||||
|
{
|
||||||
|
const tagHash = tag_.isNull ? 0 : tag_.toHash();
|
||||||
|
//Variant toHash is not nothrow at the moment, so we need to catch
|
||||||
|
//an exception that is never thrown.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//Variant toHash is not const at the moment, so we need to const-cast.
|
||||||
|
return tagHash + (cast(Value)value_).toHash();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
assert(false, "Unexpected exception caught");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return unsafeHash();
|
||||||
}
|
}
|
||||||
|
|
||||||
package:
|
package:
|
||||||
|
|
|
@ -315,7 +315,7 @@ final class Reader
|
||||||
void handleLoadCharsException(Exception e, ulong oldPosition)
|
void handleLoadCharsException(Exception e, ulong oldPosition)
|
||||||
{
|
{
|
||||||
try{throw e;}
|
try{throw e;}
|
||||||
catch(UtfException e)
|
catch(UTFException e)
|
||||||
{
|
{
|
||||||
const position = stream_.position;
|
const position = stream_.position;
|
||||||
throw new ReaderException(format("Unicode decoding error between bytes ",
|
throw new ReaderException(format("Unicode decoding error between bytes ",
|
||||||
|
|
|
@ -1609,7 +1609,7 @@ final class Scanner
|
||||||
{
|
{
|
||||||
throw new Error("While scanning a " ~ name, startMark, e.msg, mark);
|
throw new Error("While scanning a " ~ name, startMark, e.msg, mark);
|
||||||
}
|
}
|
||||||
catch(UtfException e)
|
catch(UTFException e)
|
||||||
{
|
{
|
||||||
throw new Error("While scanning a " ~ name, startMark, e.msg, mark);
|
throw new Error("While scanning a " ~ name, startMark, e.msg, mark);
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ struct ZeroString(string TypeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
///Get the string.
|
///Get the string.
|
||||||
@property string get() const
|
@property string get() const nothrow @trusted
|
||||||
in{assert(!isNull());}
|
in{assert(!isNull());}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
|
@ -51,12 +51,12 @@ struct ZeroString(string TypeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
///Compute a hash.
|
///Compute a hash.
|
||||||
hash_t toHash() const
|
hash_t toHash() const nothrow @safe
|
||||||
in{assert(!isNull);}
|
in{assert(!isNull);}
|
||||||
body
|
body
|
||||||
{
|
{
|
||||||
auto str = get();
|
auto str = get();
|
||||||
return typeid(string).getHash(&str);
|
return getHash(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
///Compare with another string.
|
///Compare with another string.
|
||||||
|
@ -68,5 +68,14 @@ struct ZeroString(string TypeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
///Is this string null (invalid)?
|
///Is this string null (invalid)?
|
||||||
@property bool isNull() const {return str_ is null;}
|
@property bool isNull() const nothrow @safe {return str_ is null;}
|
||||||
|
|
||||||
|
private:
|
||||||
|
///Hack to allow toHash to be @safe.
|
||||||
|
//
|
||||||
|
//To remove this hack, need a typeid(string).getHash() replacement that does not take a pointer.
|
||||||
|
hash_t getHash(ref string str) const nothrow @trusted
|
||||||
|
{
|
||||||
|
return typeid(string).getHash(&str);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue