Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more const in root #5409

Merged
merged 1 commit into from
Feb 6, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ public:
Module parse()
{
//printf("Module::parse(srcfile='%s') this=%p\n", srcfile->name->toChars(), this);
char* srcname = srcfile.name.toChars();
const(char)* srcname = srcfile.name.toChars();
//printf("Module::parse(srcname = '%s')\n", srcname);
isPackageFile = (strcmp(srcfile.name.name(), "package.d") == 0);
char* buf = cast(char*)srcfile.buffer;
Expand Down
14 changes: 7 additions & 7 deletions src/root/file.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct File
int _ref; // != 0 if this is a reference to someone else's buffer
ubyte* buffer; // data for our file
size_t len; // amount of data in buffer[]
FileName* name; // name of our file
const(FileName)* name; // name of our file

extern (D) this(const(char)* n)
{
Expand All @@ -40,7 +40,7 @@ struct File
_ref = 0;
buffer = null;
len = 0;
name = cast(FileName*)n;
name = n;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yebblies here's an example of as const use grows, the casts can be removed.

}

extern (C++) ~this()
Expand All @@ -59,7 +59,7 @@ struct File

extern (C++) char* toChars()
{
return name.toChars();
return cast(char*)name.toChars();
}

/*************************************
Expand All @@ -73,7 +73,7 @@ struct File
size_t size;
stat_t buf;
ssize_t numread;
char* name = this.name.toChars();
const(char)* name = this.name.toChars();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use auto?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that, and decided explicit was better when doing this conversion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That will mean we're going to have to go back and change them all again when toChars starts returning string

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll all have to be scrutinized line by line anyway, because of 0 termination, rewrite to toString, etc. It's not encapsulated well at all.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eh

//printf("File::read('%s')\n",name);
int fd = open(name, O_RDONLY);
if (fd == -1)
Expand Down Expand Up @@ -126,7 +126,7 @@ struct File
{
DWORD size;
DWORD numread;
char* name = this.name.toChars();
const(char)* name = this.name.toChars();
HANDLE h = CreateFileA(name, GENERIC_READ, FILE_SHARE_READ, null, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, null);
if (h == INVALID_HANDLE_VALUE)
goto err1;
Expand Down Expand Up @@ -173,7 +173,7 @@ struct File
version (Posix)
{
ssize_t numwritten;
char* name = this.name.toChars();
const(char)* name = this.name.toChars();
int fd = open(name, O_CREAT | O_WRONLY | O_TRUNC, (6 << 6) | (4 << 3) | 4);
if (fd == -1)
goto err;
Expand All @@ -192,7 +192,7 @@ struct File
else version (Windows)
{
DWORD numwritten;
char* name = this.name.toChars();
const(char)* name = this.name.toChars();
HANDLE h = CreateFileA(name, GENERIC_WRITE, 0, null, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, null);
if (h == INVALID_HANDLE_VALUE)
goto err;
Expand Down
12 changes: 6 additions & 6 deletions src/root/filename.d
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct FileName
this.str = mem.xstrdup(str);
}

extern (C++) bool equals(RootObject obj)
extern (C++) bool equals(const RootObject obj) const
{
return compare(obj) == 0;
}
Expand All @@ -41,7 +41,7 @@ struct FileName
return compare(name1, name2) == 0;
}

extern (C++) int compare(RootObject obj)
extern (C++) int compare(const RootObject obj) const
{
return compare(str, (cast(FileName*)obj).str);
}
Expand Down Expand Up @@ -114,7 +114,7 @@ struct FileName
}
}

extern (C++) const(char)* ext()
extern (C++) const(char)* ext() const
{
return ext(str);
}
Expand Down Expand Up @@ -176,7 +176,7 @@ struct FileName
}
}

extern (C++) const(char)* name()
extern (C++) const(char)* name() const
{
return name(str);
}
Expand Down Expand Up @@ -422,7 +422,7 @@ struct FileName
/******************************
* Return !=0 if extensions match.
*/
extern (C++) bool equalsExt(const(char)* ext)
extern (C++) bool equalsExt(const(char)* ext) const
{
return equalsExt(str, ext);
}
Expand Down Expand Up @@ -675,7 +675,7 @@ struct FileName
mem.xfree(cast(void*)str);
}

extern (C++) char* toChars()
extern (C++) const(char)* toChars() const
{
return cast(char*)str; // toChars() should really be const
}
Expand Down
2 changes: 1 addition & 1 deletion src/root/filename.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct FileName
static const char *canonicalName(const char *name);

static void free(const char *str);
char *toChars();
const char *toChars() const;
};

#endif
2 changes: 1 addition & 1 deletion src/root/outbuffer.d
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ struct OutBuffer
offset += 4;
}

extern (C++) void write(OutBuffer* buf)
extern (C++) void write(const OutBuffer* buf)
{
if (buf)
{
Expand Down
4 changes: 2 additions & 2 deletions src/root/stringtable.d
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ struct StringValue
return cast(char*)(&this + 1);
}

extern (C++) const(size_t) len()
extern (C++) size_t len() const
{
return length;
}

extern (C++) const(const(char)*) toDchars()
extern (C++) const(char)* toDchars() const
{
return cast(const(char)*)(&this + 1);
}
Expand Down