Rename ValueType -> InternalType, NormalType -> ValueType
And Value::type to Value::internalType, such that type() can be used in the next commit to get the new ValueType
This commit is contained in:
parent
730b152b19
commit
d67e02919c
|
@ -77,7 +77,7 @@ void printValue(std::ostream & str, std::set<const Value *> & active, const Valu
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (v.type) {
|
switch (v.internalType) {
|
||||||
case tInt:
|
case tInt:
|
||||||
str << v.integer;
|
str << v.integer;
|
||||||
break;
|
break;
|
||||||
|
@ -165,7 +165,7 @@ const Value *getPrimOp(const Value &v) {
|
||||||
return primOp;
|
return primOp;
|
||||||
}
|
}
|
||||||
|
|
||||||
string showType(NormalType type)
|
string showType(ValueType type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case nInt: return "an integer";
|
case nInt: return "an integer";
|
||||||
|
@ -186,7 +186,7 @@ string showType(NormalType type)
|
||||||
|
|
||||||
string showType(const Value & v)
|
string showType(const Value & v)
|
||||||
{
|
{
|
||||||
switch (v.type) {
|
switch (v.internalType) {
|
||||||
case tString: return v.string.context ? "a string with context" : "a string";
|
case tString: return v.string.context ? "a string with context" : "a string";
|
||||||
case tPrimOp:
|
case tPrimOp:
|
||||||
return fmt("the built-in function '%s'", string(v.primOp->name));
|
return fmt("the built-in function '%s'", string(v.primOp->name));
|
||||||
|
@ -205,9 +205,9 @@ string showType(const Value & v)
|
||||||
bool Value::isTrivial() const
|
bool Value::isTrivial() const
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
type != tApp
|
internalType != tApp
|
||||||
&& type != tPrimOpApp
|
&& internalType != tPrimOpApp
|
||||||
&& (type != tThunk
|
&& (internalType != tThunk
|
||||||
|| (dynamic_cast<ExprAttrs *>(thunk.expr)
|
|| (dynamic_cast<ExprAttrs *>(thunk.expr)
|
||||||
&& ((ExprAttrs *) thunk.expr)->dynamicAttrs.empty())
|
&& ((ExprAttrs *) thunk.expr)->dynamicAttrs.empty())
|
||||||
|| dynamic_cast<ExprLambda *>(thunk.expr)
|
|| dynamic_cast<ExprLambda *>(thunk.expr)
|
||||||
|
@ -1562,7 +1562,7 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
|
||||||
NixFloat nf = 0;
|
NixFloat nf = 0;
|
||||||
|
|
||||||
bool first = !forceString;
|
bool first = !forceString;
|
||||||
NormalType firstType = nString;
|
ValueType firstType = nString;
|
||||||
|
|
||||||
for (auto & i : *es) {
|
for (auto & i : *es) {
|
||||||
Value vTmp;
|
Value vTmp;
|
||||||
|
@ -1728,7 +1728,7 @@ void copyContext(const Value & v, PathSet & context)
|
||||||
std::vector<std::pair<Path, std::string>> Value::getContext()
|
std::vector<std::pair<Path, std::string>> Value::getContext()
|
||||||
{
|
{
|
||||||
std::vector<std::pair<Path, std::string>> res;
|
std::vector<std::pair<Path, std::string>> res;
|
||||||
assert(type == tString);
|
assert(internalType == tString);
|
||||||
if (string.context)
|
if (string.context)
|
||||||
for (const char * * p = string.context; *p; ++p)
|
for (const char * * p = string.context; *p; ++p)
|
||||||
res.push_back(decodeContext(*p));
|
res.push_back(decodeContext(*p));
|
||||||
|
|
|
@ -346,7 +346,7 @@ private:
|
||||||
|
|
||||||
|
|
||||||
/* Return a string representing the type of the value `v'. */
|
/* Return a string representing the type of the value `v'. */
|
||||||
string showType(NormalType type);
|
string showType(ValueType type);
|
||||||
string showType(const Value & v);
|
string showType(const Value & v);
|
||||||
|
|
||||||
/* Decode a context string ‘!<name>!<path>’ into a pair <path,
|
/* Decode a context string ‘!<name>!<path>’ into a pair <path,
|
||||||
|
|
|
@ -78,7 +78,7 @@ static void forceTrivialValue(EvalState & state, Value & value, const Pos & pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void expectType(EvalState & state, NormalType type,
|
static void expectType(EvalState & state, ValueType type,
|
||||||
Value & value, const Pos & pos)
|
Value & value, const Pos & pos)
|
||||||
{
|
{
|
||||||
forceTrivialValue(state, value, pos);
|
forceTrivialValue(state, value, pos);
|
||||||
|
|
|
@ -27,7 +27,7 @@ typedef enum {
|
||||||
tPrimOpApp,
|
tPrimOpApp,
|
||||||
tExternal,
|
tExternal,
|
||||||
tFloat
|
tFloat
|
||||||
} ValueType;
|
} InternalType;
|
||||||
|
|
||||||
// This type abstracts over all actual value types in the language,
|
// This type abstracts over all actual value types in the language,
|
||||||
// grouping together implementation details like tList*, different function
|
// grouping together implementation details like tList*, different function
|
||||||
|
@ -44,7 +44,7 @@ typedef enum {
|
||||||
nList,
|
nList,
|
||||||
nFunction,
|
nFunction,
|
||||||
nExternal
|
nExternal
|
||||||
} NormalType;
|
} ValueType;
|
||||||
|
|
||||||
class Bindings;
|
class Bindings;
|
||||||
struct Env;
|
struct Env;
|
||||||
|
@ -107,44 +107,44 @@ std::ostream & operator << (std::ostream & str, const ExternalValueBase & v);
|
||||||
struct Value
|
struct Value
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
ValueType type;
|
InternalType internalType;
|
||||||
|
|
||||||
friend std::string showType(const Value & v);
|
friend std::string showType(const Value & v);
|
||||||
friend void printValue(std::ostream & str, std::set<const Value *> & active, const Value & v);
|
friend void printValue(std::ostream & str, std::set<const Value *> & active, const Value & v);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
inline void setInt() { type = tInt; };
|
inline void setInt() { internalType = tInt; };
|
||||||
inline void setBool() { type = tBool; };
|
inline void setBool() { internalType = tBool; };
|
||||||
inline void setString() { type = tString; };
|
inline void setString() { internalType = tString; };
|
||||||
inline void setPath() { type = tPath; };
|
inline void setPath() { internalType = tPath; };
|
||||||
inline void setNull() { type = tNull; };
|
inline void setNull() { internalType = tNull; };
|
||||||
inline void setAttrs() { type = tAttrs; };
|
inline void setAttrs() { internalType = tAttrs; };
|
||||||
inline void setList1() { type = tList1; };
|
inline void setList1() { internalType = tList1; };
|
||||||
inline void setList2() { type = tList2; };
|
inline void setList2() { internalType = tList2; };
|
||||||
inline void setListN() { type = tListN; };
|
inline void setListN() { internalType = tListN; };
|
||||||
inline void setThunk() { type = tThunk; };
|
inline void setThunk() { internalType = tThunk; };
|
||||||
inline void setApp() { type = tApp; };
|
inline void setApp() { internalType = tApp; };
|
||||||
inline void setLambda() { type = tLambda; };
|
inline void setLambda() { internalType = tLambda; };
|
||||||
inline void setBlackhole() { type = tBlackhole; };
|
inline void setBlackhole() { internalType = tBlackhole; };
|
||||||
inline void setPrimOp() { type = tPrimOp; };
|
inline void setPrimOp() { internalType = tPrimOp; };
|
||||||
inline void setPrimOpApp() { type = tPrimOpApp; };
|
inline void setPrimOpApp() { internalType = tPrimOpApp; };
|
||||||
inline void setExternal() { type = tExternal; };
|
inline void setExternal() { internalType = tExternal; };
|
||||||
inline void setFloat() { type = tFloat; };
|
inline void setFloat() { internalType = tFloat; };
|
||||||
|
|
||||||
// Functions needed to distinguish the type
|
// Functions needed to distinguish the type
|
||||||
// These should be removed eventually, by putting the functionality that's
|
// These should be removed eventually, by putting the functionality that's
|
||||||
// needed by callers into methods of this type
|
// needed by callers into methods of this type
|
||||||
|
|
||||||
// normalType() == nThunk
|
// normalType() == nThunk
|
||||||
inline bool isThunk() const { return type == tThunk; };
|
inline bool isThunk() const { return internalType == tThunk; };
|
||||||
inline bool isApp() const { return type == tApp; };
|
inline bool isApp() const { return internalType == tApp; };
|
||||||
inline bool isBlackhole() const { return type == tBlackhole; };
|
inline bool isBlackhole() const { return internalType == tBlackhole; };
|
||||||
|
|
||||||
// normalType() == nFunction
|
// normalType() == nFunction
|
||||||
inline bool isLambda() const { return type == tLambda; };
|
inline bool isLambda() const { return internalType == tLambda; };
|
||||||
inline bool isPrimOp() const { return type == tPrimOp; };
|
inline bool isPrimOp() const { return internalType == tPrimOp; };
|
||||||
inline bool isPrimOpApp() const { return type == tPrimOpApp; };
|
inline bool isPrimOpApp() const { return internalType == tPrimOpApp; };
|
||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
|
@ -204,9 +204,9 @@ public:
|
||||||
|
|
||||||
// Returns the normal type of a Value. This only returns nThunk if the
|
// Returns the normal type of a Value. This only returns nThunk if the
|
||||||
// Value hasn't been forceValue'd
|
// Value hasn't been forceValue'd
|
||||||
inline NormalType normalType() const
|
inline ValueType normalType() const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (internalType) {
|
||||||
case tInt: return nInt;
|
case tInt: return nInt;
|
||||||
case tBool: return nBool;
|
case tBool: return nBool;
|
||||||
case tString: return nString;
|
case tString: return nString;
|
||||||
|
@ -224,22 +224,22 @@ public:
|
||||||
|
|
||||||
bool isList() const
|
bool isList() const
|
||||||
{
|
{
|
||||||
return type == tList1 || type == tList2 || type == tListN;
|
return internalType == tList1 || internalType == tList2 || internalType == tListN;
|
||||||
}
|
}
|
||||||
|
|
||||||
Value * * listElems()
|
Value * * listElems()
|
||||||
{
|
{
|
||||||
return type == tList1 || type == tList2 ? smallList : bigList.elems;
|
return internalType == tList1 || internalType == tList2 ? smallList : bigList.elems;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Value * const * listElems() const
|
const Value * const * listElems() const
|
||||||
{
|
{
|
||||||
return type == tList1 || type == tList2 ? smallList : bigList.elems;
|
return internalType == tList1 || internalType == tList2 ? smallList : bigList.elems;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t listSize() const
|
size_t listSize() const
|
||||||
{
|
{
|
||||||
return type == tList1 ? 1 : type == tList2 ? 2 : bigList.size;
|
return internalType == tList1 ? 1 : internalType == tList2 ? 2 : bigList.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check whether forcing this value requires a trivial amount of
|
/* Check whether forcing this value requires a trivial amount of
|
||||||
|
|
Loading…
Reference in a new issue