[pkg-d-commits] [ldc] 24/95: Misc. config tweaks (aesthetic ones + less C strings)
Matthias Klumpp
mak at moszumanska.debian.org
Thu Jul 13 20:53:57 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.3.0-beta1
in repository ldc.
commit 94e76273c4a49f1c0212670dec46c32495c45dd0
Author: Martin <noone at nowhere.com>
Date: Sat Feb 25 16:01:17 2017 +0100
Misc. config tweaks (aesthetic ones + less C strings)
---
.travis.yml | 1 -
driver/config.d | 84 ++++++++++++++++++++++++-----------------------------
driver/configfile.d | 21 ++++++++------
driver/configfile.h | 12 ++++----
4 files changed, 55 insertions(+), 63 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 503861a..0885f5b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -70,7 +70,6 @@ before_install:
export LLVM_CONFIG="llvm-$LLVM_VERSION/bin/llvm-config";
install:
- if [ "${TRAVIS_OS_NAME}" = "linux" ]; then export CC="gcc-4.9"; export CXX="g++-4.9"; fi
- - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then brew update; fi;
- eval "${DC} --version"
- pip install --user lit
- python -c "import lit; lit.main();" --version | head -n 1
diff --git a/driver/config.d b/driver/config.d
index 1b18a7c..231cc6a 100644
--- a/driver/config.d
+++ b/driver/config.d
@@ -1,4 +1,4 @@
-//===-- driver/configfile.d - LDC config file parsing -------------*- D -*-===//
+//===-- driver/config.d - LDC config file parsing -----------------*- D -*-===//
//
// LDC – the LLVM D compiler
//
@@ -49,7 +49,7 @@ class Setting
class ScalarSetting : Setting
{
- this (string name, string val)
+ this(string name, string val)
{
super(name, Type.scalar);
_val = val;
@@ -66,7 +66,7 @@ class ScalarSetting : Setting
class ArraySetting : Setting
{
- this (string name, string[] vals)
+ this(string name, string[] vals)
{
super(name, Type.array);
_vals = vals;
@@ -82,7 +82,7 @@ class ArraySetting : Setting
class GroupSetting : Setting
{
- this (string name, Setting[] children)
+ this(string name, Setting[] children)
{
super(name, Type.group);
_children = children;
@@ -104,17 +104,6 @@ Setting[] parseConfigFile(const(char)* filename)
}
-string fromStringz(const(char)* cstr)
-{
- return cstr[0 .. strlen(cstr)].idup;
-}
-
-immutable(char)* toStringz(in string s)
-{
- auto nullTerm = s ~ '\0';
- return nullTerm.ptr;
-}
-
private:
/+
@@ -176,29 +165,29 @@ string humanReadableToken(in Token tok)
{
final switch(tok)
{
- case Token.name: return "\"name\"";
- case Token.assign: return "':' or '='";
- case Token.str: return "\"string\"";
- case Token.lbrace: return "'{'";
- case Token.rbrace: return "'}'";
- case Token.lbracket: return "'['";
- case Token.rbracket: return "']'";
- case Token.semicolon: return "';'";
- case Token.comma: return "','";
- case Token.unknown: return "\"unknown token\"";
- case Token.eof: return "\"end of file\"";
+ case Token.name: return `"name"`;
+ case Token.assign: return `':' or '='`;
+ case Token.str: return `"string"`;
+ case Token.lbrace: return `'{'`;
+ case Token.rbrace: return `'}'`;
+ case Token.lbracket: return `'['`;
+ case Token.rbracket: return `']'`;
+ case Token.semicolon: return `';'`;
+ case Token.comma: return `','`;
+ case Token.unknown: return `"unknown token"`;
+ case Token.eof: return `"end of file"`;
}
}
class Parser
{
- const(char)[] filename;
+ string filename;
FILE* file;
int lineNum;
int lastChar = ' ';
- struct Ahead
+ static struct Ahead
{
Token tok;
string s;
@@ -206,26 +195,25 @@ class Parser
Ahead ahead;
Ahead* aheadp;
- this (const(char)* filename)
+ this(const(char)* filename)
{
- this.filename = filename[0 .. strlen(filename)];
+ this.filename = filename[0 .. strlen(filename)].idup;
file = fopen(filename, "r");
if (!file)
{
throw new Exception(
"could not open config file " ~
- this.filename.idup ~ " for reading");
+ this.filename ~ " for reading");
}
this.file = file;
}
void error(in string msg)
{
- enum fmt = "Error while reading config file: %s\nline %d: %s";
+ enum fmt = "Error while reading config file: %.*s\nline %d: %.*s";
char[1024] buf;
- // filename was null terminated
- auto len = snprintf(buf.ptr, 1024, fmt,
- filename.ptr, lineNum, toStringz(msg));
+ auto len = snprintf(buf.ptr, buf.length, fmt,
+ filename.length, filename.ptr, lineNum, msg.length, msg.ptr);
throw new Exception(buf[0 .. len].idup);
}
@@ -251,7 +239,7 @@ class Parser
return tok;
}
- while(isspace(lastChar))
+ while (isspace(lastChar))
{
lastChar = getChar();
}
@@ -264,11 +252,12 @@ class Parser
outStr = "/";
return Token.unknown;
}
- else do
+
+ do
{
lastChar = getChar();
- }
- while(lastChar != '\n' && lastChar != EOF);
+ } while (lastChar != '\n' && lastChar != EOF);
+
return getTok(outStr);
}
@@ -320,7 +309,7 @@ class Parser
string str;
while (lastChar == '"')
{
- while(1)
+ while (1)
{
lastChar = getChar();
if (lastChar == '"') break;
@@ -357,7 +346,7 @@ class Parser
str ~= cast(char)lastChar;
}
lastChar = getChar();
- while(isspace(lastChar)) lastChar = getChar();
+ while (isspace(lastChar)) lastChar = getChar();
}
outStr = str;
@@ -380,8 +369,8 @@ class Parser
void unexpectedTokenError(in Token tok, in Token expected, string s)
{
s = s.length ? " ("~s~")" : "";
- error("Was expecting token "~humanReadableToken(expected)~
- ". Got "~humanReadableToken(tok)~s~" instead.");
+ error("Was expecting token " ~ humanReadableToken(expected) ~
+ ". Got " ~ humanReadableToken(tok) ~ s ~ " instead.");
}
string accept(in Token expected)
@@ -398,13 +387,16 @@ class Parser
Setting[] parseConfig()
{
Setting[] res;
- while(1)
+ while (1)
{
{
string s;
auto t = getTok(s);
- if (t == Token.eof) break;
- else ungetTok(t, s);
+ if (t == Token.eof)
+ {
+ break;
+ }
+ ungetTok(t, s);
}
res ~= parseSetting();
}
diff --git a/driver/configfile.d b/driver/configfile.d
index 45e8aec..9a822b3 100644
--- a/driver/configfile.d
+++ b/driver/configfile.d
@@ -52,7 +52,7 @@ string replace(string str, string pattern, string replacement)
cap += replacement.length - pattern.length;
reserve(res, cap);
- while(str.length)
+ while (str.length)
{
if (str.length < pattern.length)
{
@@ -91,7 +91,7 @@ private:
bool readConfig(const(char)* cfPath, const(char)* section, const(char)* binDir)
{
immutable dBinDir = prepareBinDir(binDir);
- immutable dSec = fromStringz(section);
+ const dSec = section[0 .. strlen(section)];
try
{
@@ -102,7 +102,8 @@ private:
foreach (s; settings)
{
- if (s.name == dSec) {
+ if (s.name == dSec)
+ {
secSwitches = findSwitches(s);
}
else if (s.name == "default")
@@ -114,23 +115,25 @@ private:
auto switches = secSwitches ? secSwitches : defSwitches;
if (!switches)
{
- throw new Exception("could not look up switches in "~cfPath[0 .. strlen(cfPath)].idup);
+ const dCfPath = cfPath[0 .. strlen(cfPath)];
+ throw new Exception("could not look up switches in " ~ cast(string) dCfPath);
}
- auto slice = new const(char)*[switches.vals.length];
+ auto finalSwitches = new const(char)*[switches.vals.length];
foreach (i, sw; switches.vals)
{
- slice[i] = toStringz(sw.replace("%%ldcbinarypath%%", dBinDir));
+ const finalSwitch = sw.replace("%%ldcbinarypath%%", dBinDir) ~ '\0';
+ finalSwitches[i] = finalSwitch.ptr;
}
- switches_b = slice.ptr;
- switches_e = slice.ptr+slice.length;
+ switches_b = finalSwitches.ptr;
+ switches_e = finalSwitches.ptr + finalSwitches.length;
return true;
}
catch (Exception ex)
{
- fprintf(stderr, "%s\n", toStringz(ex.msg));
+ fprintf(stderr, "%.*s\n", ex.msg.length, ex.msg.ptr);
return false;
}
}
diff --git a/driver/configfile.h b/driver/configfile.h
index 15eea1d..8f184c1 100644
--- a/driver/configfile.h
+++ b/driver/configfile.h
@@ -21,8 +21,6 @@ class ConfigFile {
public:
using s_iterator = const char **;
-public:
-
bool read(const char *explicitConfFile, const char *section);
s_iterator switches_begin() { return switches_b; }
@@ -31,14 +29,14 @@ public:
std::string path() { return std::string(pathcstr); }
private:
- bool locate(std::string& pathstr);
+ bool locate(std::string &pathstr);
// implemented in D
- bool readConfig(const char* cfPath, const char* section, const char* binDir);
+ bool readConfig(const char *cfPath, const char *section, const char *binDir);
- const char *pathcstr =nullptr;
- s_iterator switches_b =nullptr;
- s_iterator switches_e =nullptr;
+ const char *pathcstr = nullptr;
+ s_iterator switches_b = nullptr;
+ s_iterator switches_e = nullptr;
};
#endif // LDC_DRIVER_CONFIGFILE_H
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list