Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/.dscanner.ini
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,5 @@ redundant_storage_classes="enabled"
redundant_storage_classes="-dmd.id,-dmd.toir,-dmd.tokens"
trust_too_much="-dmd.root.longdouble"
builtin_property_names_check="-dmd.backend.obj,-dmd.backend.code,-dmd.backend.cc"
object_const_check="-dmd.dtemplate,-dmd.backend.outbuf"
object_const_check="-dmd.dtemplate,-dmd.backend.outbuf,-dmd.root.rootobject"
final_attribute_check="-dmd.statement" ; https://github.com/dlang/dmd/pull/856
16 changes: 11 additions & 5 deletions src/dmd/dmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import dmd.root.port;
import dmd.semantic2;
import dmd.semantic3;
import dmd.target;
import dmd.utils;
import dmd.visitor;

version(Windows) {
Expand Down Expand Up @@ -1337,19 +1338,24 @@ struct ModuleDeclaration
this.isdeprecated = isdeprecated;
}

extern (C++) const(char)* toChars()
extern (C++) const(char)* toChars() const
{
OutBuffer buf;
if (packages && packages.dim)
{
for (size_t i = 0; i < packages.dim; i++)
foreach (pid; *packages)
{
Identifier pid = (*packages)[i];
buf.writestring(pid.toChars());
buf.writestring(pid.toString());
buf.writeByte('.');
}
}
buf.writestring(id.toChars());
buf.writestring(id.toString());
return buf.extractString();
}

/// Provide a human readable representation
extern (D) const(char)[] toString() const
{
return this.toChars().toDString;
}
}
9 changes: 1 addition & 8 deletions src/dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#pragma once
#endif

#include "root/dcompat.h"
#include "ctfloat.h"
#include "outbuffer.h"
#include "filename.h"
Expand Down Expand Up @@ -292,14 +293,6 @@ typedef uint32_t d_uns32;
typedef int64_t d_int64;
typedef uint64_t d_uns64;

// Represents a D [ ] array
template<typename T>
struct DArray
{
size_t length;
T *ptr;
};

// file location
struct Loc
{
Expand Down
33 changes: 33 additions & 0 deletions src/dmd/hdrgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -3347,14 +3347,36 @@ extern (C++) const(char)* stcToChars(ref StorageClass stc)
return null;
}


/**
* Returns:
* a human readable representation of `stc`
*/
extern (D) const(char)[] stcToString(ref StorageClass stc)
{
return stcToChars(stc).toDString;
}

extern (C++) void trustToBuffer(OutBuffer* buf, TRUST trust)
{
const(char)* p = trustToChars(trust);
if (p)
buf.writestring(p);
}

/**
* Returns:
* a human readable representation of `trust`,
* which is the token `trust` corresponds to
*/
extern (C++) const(char)* trustToChars(TRUST trust)
{
/// Works because we return a literal
return trustToString(trust).ptr;
}

/// Ditto
extern (D) string trustToString(TRUST trust)
{
final switch (trust)
{
Expand Down Expand Up @@ -3416,7 +3438,18 @@ extern (C++) void protectionToBuffer(OutBuffer* buf, Prot prot)
}
}

/**
* Returns:
* a human readable representation of `kind`
*/
extern (C++) const(char)* protectionToChars(Prot.Kind kind)
{
// Null terminated because we return a literal
return protectionToString(kind).ptr;
}

/// Ditto
extern (D) string protectionToString(Prot.Kind kind)
{
final switch (kind)
{
Expand Down
2 changes: 1 addition & 1 deletion src/dmd/identifier.d
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ nothrow:
return name;
}

extern (D) const(char)[] toString() const pure
extern (D) override const(char)[] toString() const pure
{
return name[0 .. len];
}
Expand Down
Loading