diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2013-01-03 08:10:25 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2013-01-03 08:10:25 +0000 |
commit | 2853156a2bce535bcaa440c37cf872916f76c03b (patch) | |
tree | 8e161033a9bac8274dcaca05940964b91cdb2bfc /sca-cpp/trunk/kernel | |
parent | 55607ea78e10832838d52fdb17cbdfe4355c3265 (diff) |
Refactoring, rename isNil to isNull.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1428206 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/kernel')
-rw-r--r-- | sca-cpp/trunk/kernel/element.hpp | 28 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/function.hpp | 4 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/kernel-test.cpp | 18 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/list.hpp | 68 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/parallel-test.cpp | 6 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/parallel.hpp | 6 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/sstream.hpp | 14 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/tree.hpp | 36 | ||||
-rw-r--r-- | sca-cpp/trunk/kernel/value.hpp | 16 |
9 files changed, 98 insertions, 98 deletions
diff --git a/sca-cpp/trunk/kernel/element.hpp b/sca-cpp/trunk/kernel/element.hpp index d8907c8d21..4798570982 100644 --- a/sca-cpp/trunk/kernel/element.hpp +++ b/sca-cpp/trunk/kernel/element.hpp @@ -43,7 +43,7 @@ const string atsign("@"); * Returns true if a value is an element. */ inline const bool isElement(const value& v) { - if (!isList(v) || isNil(v) || element != car<value>(v)) + if (!isList(v) || isNull(v) || element != car<value>(v)) return false; return true; } @@ -52,7 +52,7 @@ inline const bool isElement(const value& v) { * Returns true if a value is an attribute. */ inline const bool isAttribute(const value& v) { - if (!isList(v) || isNil(v) || attribute != car<value>(v)) + if (!isList(v) || isNull(v) || attribute != car<value>(v)) return false; return true; } @@ -82,7 +82,7 @@ inline const value elementName(const list<value>& l) { * Returns true if an element has children. */ inline const bool elementHasChildren(const list<value>& l) { - return !isNil(cddr(l)); + return !isNull(cddr(l)); } /** @@ -99,7 +99,7 @@ inline const bool elementHasValue(const list<value>& l) { const list<value> r = reverse(l); if (isSymbol(car(r))) return false; - if(isList(car(r)) && !isNil((list<value>)car(r)) && isSymbol(car<value>(car(r)))) + if(isList(car(r)) && !isNull((list<value>)car(r)) && isSymbol(car<value>(car(r)))) return false; return true; } @@ -118,7 +118,7 @@ inline const bool elementToValueIsList(const value& v) { if (!isList(v)) return false; const list<value> l = v; - return (isNil(l) || !isSymbol(car(l))); + return (isNull(l) || !isSymbol(car(l))); } inline const value elementToValue(const value& t) { @@ -159,7 +159,7 @@ inline const bool elementToValueIsSymbol(const value& v) { if (!isList(v)) return false; const list<value> l = v; - if (isNil(l)) + if (isNull(l)) return false; if (!isSymbol(car(l))) return false; @@ -167,7 +167,7 @@ inline const bool elementToValueIsSymbol(const value& v) { } inline const list<value> elementToValueGroupValues(const value& v, const list<value>& l) { - if (isNil(l) || !elementToValueIsSymbol(v) || !elementToValueIsSymbol(car(l))) + if (isNull(l) || !elementToValueIsSymbol(v) || !elementToValueIsSymbol(car(l))) return cons(v, l); if (car<value>(car(l)) != car<value>(v)) return cons(v, l); @@ -181,7 +181,7 @@ inline const list<value> elementToValueGroupValues(const value& v, const list<va } inline const list<value> elementsToValues(const list<value>& e) { - if (isNil(e)) + if (isNull(e)) return e; return elementToValueGroupValues(elementToValue(car(e)), elementsToValues(cdr(e))); } @@ -193,9 +193,9 @@ inline const value valueToElement(const value& t) { const list<value> valuesToElements(const list<value>& l); // Convert a name value pair - if (isList(t) && !isNil((list<value>)t) && isSymbol(car<value>(t))) { + if (isList(t) && !isNull((list<value>)t) && isSymbol(car<value>(t))) { const value n = car<value>(t); - const value v = isNil(cdr<value>(t))? nilValue : cadr<value>(t); + const value v = isNull(cdr<value>(t))? nilValue : cadr<value>(t); // Convert a single value to an attribute or an element if (!isList(v)) { @@ -205,7 +205,7 @@ inline const value valueToElement(const value& t) { } // Convert a list value - if (isNil((list<value>)v) || !isSymbol(car<value>(v))) + if (isNull((list<value>)v) || !isSymbol(car<value>(v))) return cons(element, cons(n, mklist<value>(valuesToElements(v)))); // Convert a nested name value pair value @@ -222,7 +222,7 @@ inline const value valueToElement(const value& t) { * Convert a list of values to a list of elements. */ inline const list<value> valuesToElements(const list<value>& l) { - if (isNil(l)) + if (isNull(l)) return l; return cons<value>(valueToElement(car(l)), valuesToElements(cdr(l))); } @@ -234,7 +234,7 @@ inline const value attributeValue(const value& name, const list<value>& l) { const list<value> f = filter<value>([name](const value& v) { return isAttribute(v) && attributeName((list<value>)v) == name; }, l); - if (isNil(f)) + if (isNull(f)) return nilValue; return caddr<value>(car(f)); } @@ -253,7 +253,7 @@ inline const list<value> elementChildren(const value& name, const list<value>& l */ inline const value elementChild(const value& name, const list<value>& l) { const list<value> f = elementChildren(name, l); - if (isNil(f)) + if (isNull(f)) return nilValue; return car(f); } diff --git a/sca-cpp/trunk/kernel/function.hpp b/sca-cpp/trunk/kernel/function.hpp index 0a88cf51d9..e2ba8ad0ad 100644 --- a/sca-cpp/trunk/kernel/function.hpp +++ b/sca-cpp/trunk/kernel/function.hpp @@ -160,7 +160,7 @@ public: } template<typename S> friend ostream& operator<<(ostream&, const lambda<S>&); - template<typename S> friend const bool isNil(const lambda<S>& l) noexcept; + template<typename S> friend const bool isNull(const lambda<S>& l) noexcept; private: typedef Callable<R,P...> CallableType; @@ -179,7 +179,7 @@ template<typename S> inline ostream& operator<<(ostream& out, const lambda<S>& l /** * Return true if a lambda is nil. */ -template<typename S> inline const bool isNil(const lambda<S>& l) noexcept { +template<typename S> inline const bool isNull(const lambda<S>& l) noexcept { return (const void*)l.callable == NULL; } diff --git a/sca-cpp/trunk/kernel/kernel-test.cpp b/sca-cpp/trunk/kernel/kernel-test.cpp index 4c68975961..5d8b8039b4 100644 --- a/sca-cpp/trunk/kernel/kernel-test.cpp +++ b/sca-cpp/trunk/kernel/kernel-test.cpp @@ -225,7 +225,7 @@ const bool testMutable() { } { gc_mutable_ref<value> v; - assert(isNil((value)v)); + assert(isNull((value)v)); v = 1; assert(v == 1); } @@ -386,7 +386,7 @@ ostream& operator<<(ostream& out, const Element& v) { const bool testCons() { assert(car(cons(2, mklist(3))) == 2); assert(car(cdr(cons(2, mklist(3)))) == 3); - assert(isNil(cdr(cdr(cons(2, mklist(3)))))); + assert(isNull(cdr(cdr(cons(2, mklist(3)))))); assert(cons(Element(1), mklist(Element(2))) == mklist(Element(1), Element(2))); return true; @@ -471,7 +471,7 @@ const bool testAppend() { assert(car(append(mklist(1), mklist(2))) == 1); assert(car(cdr(append(mklist(1), mklist(2)))) == 2); assert(car(cdr(cdr(append(mklist(1), mklist(2, 3))))) == 3); - assert(isNil(cdr(cdr(cdr(append(mklist(1), mklist(2, 3))))))); + assert(isNull(cdr(cdr(cdr(append(mklist(1), mklist(2, 3))))))); assert(list<int>() + 1 + 2 + 3 == mklist(1, 2, 3)); return true; @@ -497,12 +497,12 @@ const bool testComplex() { const list<Complex> p = mklist(Complex(1, 2), Complex(3, 4)); assert(car(p).x == 1); assert(car(cdr(p)).x == 3); - assert(isNil(cdr(cdr(p)))); + assert(isNull(cdr(cdr(p)))); return true; } const bool testMap() { - assert(isNil(map<int, int>(square, list<int>()))); + assert(isNull(map<int, int>(square, list<int>()))); const list<int> m = map<int, int>(square, mklist(2, 3)); assert(car(m) == 4); @@ -535,7 +535,7 @@ const bool testFilter() { } const bool testMember() { - assert(isNil(member(4, mklist(1, 2, 3)))); + assert(isNull(member(4, mklist(1, 2, 3)))); assert(car(member(1, mklist(1, 2, 3))) == 1); assert(car(member(2, mklist(1, 2, 3))) == 2); assert(car(member(3, mklist(1, 2, 3))) == 3); @@ -543,7 +543,7 @@ const bool testMember() { } const bool testReverse() { - assert(isNil(reverse(list<int>()))); + assert(isNull(reverse(list<int>()))); assert(car(reverse(mklist(1, 2, 3))) == 3); assert(cadr(reverse(mklist(1, 2, 3))) == 2); return true; @@ -566,7 +566,7 @@ const bool testSubst() { const bool testAssoc() { const list<list<string> > l = mklist(mklist<string>("x", "X"), mklist<string>("a", "A"), mklist<string>("y", "Y"), mklist<string>("a", "AA")); assert(assoc<string>("a", l) == mklist<string>("a", "A")); - assert(isNil(assoc<string>("z", l))); + assert(isNull(assoc<string>("z", l))); const list<list<string> > l3 = mklist(mklist<string>("x", "X"), mklist<string>("a", "A"), mklist<string>("a", "AA")); assert(delAssoc<string>("y", l) == l3); @@ -762,7 +762,7 @@ const bool testBinaryTreeAssoc() { assert(rbtreeAssoc<value>("a", bt) == mklist<value>("a", "aa")); assert(rbtreeAssoc<value>("b", bt) == mklist<value>("b", "bb")); assert(rbtreeAssoc<value>("f", bt) == mklist<value>("f", "ff")); - assert(isNil(rbtreeAssoc<value>("x", bt))); + assert(isNull(rbtreeAssoc<value>("x", bt))); return true; } diff --git a/sca-cpp/trunk/kernel/list.hpp b/sca-cpp/trunk/kernel/list.hpp index 02df2c2dc5..753b33b6a0 100644 --- a/sca-cpp/trunk/kernel/list.hpp +++ b/sca-cpp/trunk/kernel/list.hpp @@ -120,9 +120,9 @@ public: inline const bool operator==(const list<T>& p) const noexcept { if(this == &p) return true; - if(isNil(cdr)) - return isNil(p.cdr); - if(isNil(p.cdr)) + if(isNull(cdr)) + return isNull(p.cdr); + if(isNull(p.cdr)) return false; if(!(car == p.car)) return false; @@ -134,9 +134,9 @@ public: inline const bool operator<(const list<T>& p) const noexcept { if(this == &p) return false; - if (isNil(cdr)) - return !isNil(p.cdr); - if (isNil(p.cdr)) + if (isNull(cdr)) + return !isNull(p.cdr); + if (isNull(p.cdr)) return false; if (car < p.car) return true; @@ -148,9 +148,9 @@ public: inline const bool operator>(const list<T>& p) const noexcept { if(this == &p) return false; - if (isNil(cdr)) + if (isNull(cdr)) return false; - if (isNil(p.cdr)) + if (isNull(p.cdr)) return true; if (car > p.car) return true; @@ -173,7 +173,7 @@ private: string watch; #endif - template<typename X> friend const bool isNil(const list<X>& p) noexcept; + template<typename X> friend const bool isNull(const list<X>& p) noexcept; template<typename X> friend const X car(const list<X>& p) noexcept; template<typename X> friend const list<X> cdr(const list<X>& p) noexcept; @@ -188,7 +188,7 @@ private: * to watch than the list itself in a debugger. */ template<typename T> inline const string watchList(const list<T>& p) noexcept { - if(isNil(p)) + if(isNull(p)) return "()"; odebugstream os; os << "(" << car(p) << " ...)"; @@ -200,22 +200,22 @@ template<typename T> inline const string watchList(const list<T>& p) noexcept { /** * Returns true if the given list is nil. */ -template<typename T> inline const bool isNil(const list<T>& p) noexcept { - return isNil(p.cdr); +template<typename T> inline const bool isNull(const list<T>& p) noexcept { + return isNull(p.cdr); } /** * Write a list to an output stream. */ template<typename T> inline ostream& writeHelper(ostream& out, const list<T>& l) noexcept { - if (isNil(l)) + if (isNull(l)) return out; out << " " << car(l); return writeHelper(out, cdr(l)); } template<typename T> inline ostream& operator<<(ostream& out, const list<T>& l) noexcept { - if(isNil(l)) + if(isNull(l)) return out << "()"; out << "(" << car(l); writeHelper<T>(out, cdr(l)); @@ -294,7 +294,7 @@ template<typename T> inline const list<T> mklist(const T& a, const T& b, const T */ template<typename T> inline const T car(const list<T>& p) noexcept { // Abort if trying to access the car of a nil list - assertOrFail(!isNil(p.cdr)); + assertOrFail(!isNull(p.cdr)); return p.car; } @@ -401,7 +401,7 @@ template<typename T> inline const list<T> cdddddddr(const list<T>& p) noexcept { */ template<typename T> inline const size_t length(const list<T>& p) noexcept { const lambda<size_t(const size_t, const list<T>&)> lengthRef = [&lengthRef](const size_t c, const list<T>& p) -> const size_t { - if(isNil(p)) + if(isNull(p)) return c; return lengthRef(c + 1, cdr(p)); }; @@ -412,7 +412,7 @@ template<typename T> inline const size_t length(const list<T>& p) noexcept { * Appends a list and a lambda function returning a list. */ template<typename T> inline const list<T> append(const list<T>&a, const lambda<const list<T>()>& fb) noexcept { - if(isNil(a)) + if(isNull(a)) return fb(); return cons<T>(car(a), [a, fb]() { return append(cdr(a), fb); }); } @@ -439,7 +439,7 @@ template<typename T, typename V> const list<T> inline operator+(const list<T>& l * Run a map lambda function on a list. */ template<typename T, typename R> inline const list<R> map(const lambda<const R(const T)>& f, const list<T>& p) noexcept { - if(isNil(p)) + if(isNull(p)) return list<R> (); return cons(f(car(p)), map(f, cdr(p))); } @@ -449,7 +449,7 @@ template<typename T, typename R> inline const list<R> map(const lambda<const R(c */ template<typename T, typename R> inline const R reduce(const lambda<const R(const R, const T)>& f, const R& initial, const list<T>& p) noexcept { const lambda<const R(const R&, const list<T>&p)> reduceAccumulate = [f, &reduceAccumulate](const R& acc, const list<T>& p) -> R { - if(isNil(p)) + if(isNull(p)) return acc; return reduceAccumulate(f(acc, car(p)), cdr(p)); }; @@ -458,7 +458,7 @@ template<typename T, typename R> inline const R reduce(const lambda<const R(cons template<typename T, typename R> inline const R reduceRight(const lambda<const R(const T, const R)>& f, const R& initial, const list<T>& p) noexcept { const lambda<const R(const list<T>&p, const R&)> reduceRightAccumulate = [f, &reduceRightAccumulate](const list<T>& p, const R& acc) -> R { - if(isNil(p)) + if(isNull(p)) return acc; return reduceRightAccumulate(cdr(p), f(car(p), acc)); }; @@ -469,7 +469,7 @@ template<typename T, typename R> inline const R reduceRight(const lambda<const R * Run a filter lambda function on a list. */ template<typename T> inline const list<T> filter(const lambda<const bool(const T)>& f, const list<T>& p) noexcept { - if(isNil(p)) + if(isNull(p)) return list<T> (); if(f(car(p))) { const lambda<const list<T>(const lambda<const bool(const T)>, const list<T>)> ff(filter<T>); @@ -482,7 +482,7 @@ template<typename T> inline const list<T> filter(const lambda<const bool(const T * Returns a list pointing to a member of a list. */ template<typename T> inline const list<T> member(const T& t, const list<T>& p) noexcept { - if(isNil(p)) + if(isNull(p)) return list<T> (); if(t == car(p)) return p; @@ -493,7 +493,7 @@ template<typename T> inline const list<T> member(const T& t, const list<T>& p) n * Reverse a list. */ template<typename T> inline const list<T> reverseIter(const list<T>& acc, const list<T>& p) noexcept { - if(isNil(p)) + if(isNull(p)) return acc; return reverseIter(cons(car(p), acc), cdr(p)); } @@ -528,7 +528,7 @@ template<typename T> inline const T listRef(const list<T>& l, const size_t i) no template<typename T> inline const list<T> listTail(const list<T>& l, const size_t k) noexcept { if(k == 0) return l; - if(isNil(l)) + if(isNull(l)) return l; return listTail(cdr(l), k - 1); } @@ -537,7 +537,7 @@ template<typename T> inline const list<T> listTail(const list<T>& l, const size_ * Substitute elements in a list. */ template<typename T> inline const list<T> subst(const T& o, const T& n, const list<T>& p) noexcept { - if(isNil(p)) + if(isNull(p)) return p; if(o == car(p)) return cons<T>(n, subst(o, n, cdr(p))); @@ -548,7 +548,7 @@ template<typename T> inline const list<T> subst(const T& o, const T& n, const li * Returns the first pair matching a key from a list of key value pairs. */ template<typename T> inline const list<T> assoc(const T& k, const list<list<T> >& p) noexcept { - if(isNil(p)) + if(isNull(p)) return list<T>(); if(k == car(car(p))) return car(p); @@ -560,7 +560,7 @@ template<typename T> inline const list<T> assoc(const T& k, const list<list<T> > * Requires T to support isList and cast to list<T>. */ template<typename T> inline const list<T> assoc(const T& k, const list<T>& p) noexcept { - if(isNil(p)) + if(isNull(p)) return list<T>(); const T c = car(p); if(isList(c) && k == car<T>(c)) @@ -572,7 +572,7 @@ template<typename T> inline const list<T> assoc(const T& k, const list<T>& p) no * Returns a list of lists containing elements from two input lists. */ template<typename T> inline const list<list<T> > zip(const list<T>& a, const list<T>& b) noexcept { - if (isNil(a) || isNil(b)) + if (isNull(a) || isNull(b)) return list<list<T> >(); return cons<list<T> >(mklist<T>(car(a), car(b)), zip(cdr(a), cdr(b))); } @@ -581,13 +581,13 @@ template<typename T> inline const list<list<T> > zip(const list<T>& a, const lis * Converts a list of key value pairs to a list containing the list of keys and the list of values. */ template<typename T> inline const list<T> unzipKeys(const list<list<T> >& l) noexcept { - if (isNil(l)) + if (isNull(l)) return list<T>(); return cons(car(car(l)), unzipKeys(cdr(l))); } template<typename T> inline const list<T> unzipValues(const list<list<T> >& l) noexcept { - if (isNil(l)) + if (isNull(l)) return list<T>(); return cons(cadr(car(l)), unzipValues(cdr(l))); } @@ -600,7 +600,7 @@ template<typename T> inline const list<list<T> > unzip(const list<list<T> >& l) * Delete assocs matching a key from a list of assocs. */ template<typename T> inline const list<list<T> > delAssoc(const T& k, const list<list<T> >& p) noexcept { - if(isNil(p)) + if(isNull(p)) return p; if(k == car(car(p))) return delAssoc(k, cdr(p)); @@ -612,7 +612,7 @@ template<typename T> inline const list<list<T> > delAssoc(const T& k, const list * Requires T to support isList, isAssoc, and cast to list<T>. */ template<typename T> inline const list<T> delAssoc(const T& k, const list<T>& p) noexcept { - if(isNil(p)) + if(isNull(p)) return p; const T c = car(p); if(isList(c) && k == car<T>(c)) @@ -624,7 +624,7 @@ template<typename T> inline const list<T> delAssoc(const T& k, const list<T>& p) * Substitute assocs with matching keys in a list of assocs. */ template<typename T> inline const list<list<T> > substAssoc(const T& k, const list<T>& n, const list<list<T> >& p, const bool add = false) noexcept { - if(isNil(p)) + if(isNull(p)) return add? mklist<list<T> >(n) : p; if(k == car(car(p))) return cons<list<T> >(n, substAssoc(k, n, cdr(p), false)); @@ -636,7 +636,7 @@ template<typename T> inline const list<list<T> > substAssoc(const T& k, const li * Requires T to support isList, isAssoc, and cast to list<T>. */ template<typename T> inline const list<T> substAssoc(const T& k, const list<T>& n, const list<T>& p, const bool add = false) noexcept { - if(isNil(p)) + if(isNull(p)) return add? mklist<T>(n) : p; const T c = car(p); if(isList(c) && k == car<T>(c)) diff --git a/sca-cpp/trunk/kernel/parallel-test.cpp b/sca-cpp/trunk/kernel/parallel-test.cpp index 895bb91eb8..9440cbaafd 100644 --- a/sca-cpp/trunk/kernel/parallel-test.cpp +++ b/sca-cpp/trunk/kernel/parallel-test.cpp @@ -109,7 +109,7 @@ const list<future<int> > submitSquares(worker& w, const int max, const int i) { } bool checkSquareResults(const list<future<int> > r, int i) { - if (isNil(r)) + if (isNull(r)) return true; assert(car(r) == i * i); checkSquareResults(cdr(r), i + 1); @@ -160,7 +160,7 @@ const list<future<long int> > submitTLSSets(worker& w, wqueue<bool>& wq, wqueue< } const bool checkTLSSets(const list<future<long int> > s) { - if (isNil(s)) + if (isNull(s)) return true; assert(car(s) == 0); return checkTLSSets(cdr(s)); @@ -174,7 +174,7 @@ const list<future<bool> > submitTLSChecks(worker& w, wqueue<bool>& wq, wqueue<bo } const bool checkTLSResults(const list<future<bool> > r) { - if (isNil(r)) + if (isNull(r)) return true; assert(car(r) == true); return checkTLSResults(cdr(r)); diff --git a/sca-cpp/trunk/kernel/parallel.hpp b/sca-cpp/trunk/kernel/parallel.hpp index 8b01bb819f..6981a67831 100644 --- a/sca-cpp/trunk/kernel/parallel.hpp +++ b/sca-cpp/trunk/kernel/parallel.hpp @@ -274,7 +274,7 @@ template<typename R> inline const future<R> submit(const worker& w, const lambda * Enqueues shutdown requests. */ inline const bool shutdownEnqueue(const list<pthread_t>& threads, wqueue<blambda>& work) noexcept { - if (isNil(threads)) + if (isNull(threads)) return true; enqueue(work, result(false)); return shutdownEnqueue(cdr(threads), work); @@ -284,7 +284,7 @@ inline const bool shutdownEnqueue(const list<pthread_t>& threads, wqueue<blambda * Waits for shut down threads to terminate. */ inline const bool shutdownJoin(const list<pthread_t>& threads) noexcept { - if (isNil(threads)) + if (isNull(threads)) return true; pthread_join(car(threads), NULL); return shutdownJoin(cdr(threads)); @@ -303,7 +303,7 @@ inline const bool shutdown(const worker& w) noexcept { * Cancel a worker. */ inline const bool cancel(const list<pthread_t>& threads) noexcept { - if (isNil(threads)) + if (isNull(threads)) return true; pthread_cancel(car(threads)); return cancel(cdr(threads)); diff --git a/sca-cpp/trunk/kernel/sstream.hpp b/sca-cpp/trunk/kernel/sstream.hpp index dbdc7414a1..56f1c1c867 100644 --- a/sca-cpp/trunk/kernel/sstream.hpp +++ b/sca-cpp/trunk/kernel/sstream.hpp @@ -46,7 +46,7 @@ inline void* stream_memcpy(void* t, const void* s, const size_t n) { * Write a list of strings into a buffer. */ const bool writeList(const list<string>& l, char* const buf) { - if (isNil(l)) + if (isNull(l)) return true; const string c = car(l); char* b = buf - length(c); @@ -114,7 +114,7 @@ public: private: inline const string str() { spill(); - if (isNil((const list<string>)buf)) + if (isNull((const list<string>)buf)) return emptyString; char* const sbuf = gc_cnew(len + 1); writeList(buf, sbuf + len); @@ -239,10 +239,10 @@ inline const list<string> tokenize(const char* const sep, const string& str) { inline const string join(const char* const sep, const list<string>& l) { ostringstream os; const lambda<ostringstream&(const char* const, const list<string>&, ostringstream&)> join = [&join](const char* const sep, const list<string>& l, ostringstream& os) -> ostringstream& { - if (isNil(l)) + if (isNull(l)) return os; os << car(l); - if (!isNil(cdr(l))) + if (!isNull(cdr(l))) os << sep; return join(sep, cdr(l), os); }; @@ -277,7 +277,7 @@ inline const list<string> fragment(const list<string>& l, const size_t max) { * Write a list of strings to an output stream. */ inline ostream& write(const list<string>& l, ostream& os) { - if(isNil(l)) + if(isNull(l)) return os; os << car(l); return write(cdr(l), os); @@ -287,9 +287,9 @@ inline ostream& write(const list<string>& l, ostream& os) { * Convert a list of strings to a string. */ inline const string write(const list<string>& l) { - if (isNil(l)) + if (isNull(l)) return emptyString; - if (isNil(cdr(l))) + if (isNull(cdr(l))) return car(l); ostringstream os; write(l, os); diff --git a/sca-cpp/trunk/kernel/tree.hpp b/sca-cpp/trunk/kernel/tree.hpp index d350879ce7..a5d0e3d5b0 100644 --- a/sca-cpp/trunk/kernel/tree.hpp +++ b/sca-cpp/trunk/kernel/tree.hpp @@ -40,13 +40,13 @@ namespace tuscany { * Requires T to support isList, isAssoc, and cast to list<T>. */ template<typename T> inline const list<T> treeDelAssoc(const list<T>& k, const list<T>& l) noexcept { - if (isNil(k) || isNil(l)) + if (isNull(k) || isNull(l)) return l; const list<T> lv = l; // If list is an assoc and matches, skip it if (isAssoc(lv)) { - if (car<T>(lv) == car(k) && isNil(cdr(k))) + if (car<T>(lv) == car(k) && isNull(cdr(k))) return list<T>(); } @@ -56,23 +56,23 @@ template<typename T> inline const list<T> treeDelAssoc(const list<T>& k, const l if (!isList(a)) return cons<T>(a, treeDelAssoc<T>(k, cdr(lv))); const list<T> da = treeDelAssoc<T>(k, a); - return isNil(da)? treeDelAssoc<T>(k, cdr(lv)) : cons<T>(da, treeDelAssoc<T>(k, cdr(lv))); + return isNull(da)? treeDelAssoc<T>(k, cdr(lv)) : cons<T>(da, treeDelAssoc<T>(k, cdr(lv))); } // If we found a match, skip it and lookup children and rest of the list if (car<T>(a) == car(k)) { - if (isNil(cdr(k))) + if (isNull(cdr(k))) return treeDelAssoc<T>(k, cdr(lv)); return cons<T>(cons<T>(car<T>(a), treeDelAssoc<T>(cdr(k), cdr<T>(a))), treeDelAssoc<T>(k, cdr(lv))); } // No match, lookup children and rest of the list - if (isNil(cdr<T>(a))) + if (isNull(cdr<T>(a))) return cons<T>(a, treeDelAssoc<T>(k, cdr(lv))); if (!isList(cadr<T>(a))) return cons<T>(cons<T>(car<T>(a), cons<T>(cadr<T>(a), treeDelAssoc<T>(k, cddr<T>(a)))), treeDelAssoc<T>(k, cdr(lv))); const list<T> da = treeDelAssoc<T>(k, cadr<T>(a)); - if (isNil(da)) + if (isNull(da)) return cons<T>(cons<T>(car<T>(a), treeDelAssoc<T>(k, cddr<T>(a))), treeDelAssoc<T>(k, cdr(lv))); return cons<T>(cons<T>(car<T>(a), cons<T>(da, treeDelAssoc<T>(k, cddr<T>(a)))), treeDelAssoc<T>(k, cdr(lv))); } @@ -83,12 +83,12 @@ template<typename T> inline const list<T> treeDelAssoc(const list<T>& k, const l * Requires T to support isList, isAssoc, and cast to list<T>. */ template<typename T> inline const list<T> treeSubstAssoc(const list<T>& k, const list<T>& n, const list<T>& lv) noexcept { - if (isNil(k) || isNil(lv)) + if (isNull(k) || isNull(lv)) return lv; // If list is an assoc and matches, substitute it if (isAssoc(lv)) { - if (car<T>(lv) == car(k) && isNil(cdr(k))) + if (car<T>(lv) == car(k) && isNull(cdr(k))) return n; } @@ -102,13 +102,13 @@ template<typename T> inline const list<T> treeSubstAssoc(const list<T>& k, const // If we found a match, substitute it and lookup children and rest of the list if (car<T>(a) == car(k)) { - if (isNil(cdr(k))) + if (isNull(cdr(k))) return cons<T>(n, treeSubstAssoc<T>(k, n, cdr(lv))); return cons<T>(cons<T>(car<T>(a), treeSubstAssoc<T>(cdr(k), n, cdr<T>(a))), treeSubstAssoc<T>(k, n, cdr(lv))); } // No match, lookup children and rest of the list - if (isNil(cdr<T>(a))) + if (isNull(cdr<T>(a))) return cons<T>(a, treeSubstAssoc<T>(k, n, cdr(lv))); if (!isList(cadr<T>(a))) return cons<T>(cons<T>(car<T>(a), cons<T>(cadr<T>(a), treeSubstAssoc<T>(k, n, cddr<T>(a)))), treeSubstAssoc<T>(k, n, cdr(lv))); @@ -121,12 +121,12 @@ template<typename T> inline const list<T> treeSubstAssoc(const list<T>& k, const * Requires T to support isList, isAssoc, and cast to list<T>. */ template<typename T> inline const list<T> treeSelectAssoc(const list<T>& k, const list<T>& lv) noexcept { - if (isNil(k) || isNil(lv)) + if (isNull(k) || isNull(lv)) return list<T>(); // If list is an assoc and matches, select it if (isAssoc(lv)) { - if (car<T>(lv) == car(k) && isNil(cdr(k))) + if (car<T>(lv) == car(k) && isNull(cdr(k))) return mklist<T>(lv); } @@ -140,13 +140,13 @@ template<typename T> inline const list<T> treeSelectAssoc(const list<T>& k, cons // If we found a match, select it and lookup children and rest of the list if (car<T>(a) == car(k)) { - if (isNil(cdr(k))) + if (isNull(cdr(k))) return cons<T>(a, treeSelectAssoc<T>(k, cdr(lv))); return append<T>(treeSelectAssoc<T>(cdr(k), cdr<T>(a)), treeSelectAssoc<T>(k, cdr(lv))); } // No match, lookup children and rest of the list - if (isNil(cdr<T>(a))) + if (isNull(cdr<T>(a))) return treeSelectAssoc<T>(k, cdr(lv)); if (!isList(cadr<T>(a))) return append<T>(treeSelectAssoc<T>(k, cddr<T>(a)), treeSelectAssoc<T>(k, cdr(lv))); @@ -164,7 +164,7 @@ template<typename T> inline const list<T> mkrbtree(const T& e, const list<T>& le * Find a leaf with the given key in a rooted binary tree. */ template<typename T> inline const list<T> rbtreeAssoc(const T& k, const list<T>& tree) { - if (isNil(tree)) + if (isNull(tree)) return tree; if (k == car<T>(car(tree))) return car(tree); @@ -177,7 +177,7 @@ template<typename T> inline const list<T> rbtreeAssoc(const T& k, const list<T>& * Construct a new rooted binary tree from a leaf and a tree. */ template<typename T> inline const list<T> rbtreeCons(const T& e, const list<T>& tree) { - if (isNil(tree)) + if (isNull(tree)) return mkrbtree(e, list<T>(), list<T>()); if (e == car(tree)) return tree; @@ -190,7 +190,7 @@ template<typename T> inline const list<T> rbtreeCons(const T& e, const list<T>& * Make a rooted binary tree from an unordered list of leaves. */ template<typename T> inline const list<T> mkrbtree(const list<T>& l) { - if (isNil(l)) + if (isNull(l)) return l; return rbtreeCons(car(l), mkrbtree(cdr(l))); } @@ -199,7 +199,7 @@ template<typename T> inline const list<T> mkrbtree(const list<T>& l) { * Convert a rooted binary tree to an ordered list of leaves. */ template<typename T> inline const list<T> flatten(const list<T>& tree) { - if (isNil(tree)) + if (isNull(tree)) return tree; return append<T>(flatten<T>(cadr(tree)), cons<T>(car(tree), flatten<T>(caddr(tree)))); } diff --git a/sca-cpp/trunk/kernel/value.hpp b/sca-cpp/trunk/kernel/value.hpp index d5ce34084a..660ece0c25 100644 --- a/sca-cpp/trunk/kernel/value.hpp +++ b/sca-cpp/trunk/kernel/value.hpp @@ -489,7 +489,7 @@ inline const value::ValueType type(const value& v) noexcept { /** * Returns true if a value is nil. */ -inline const bool isNil(const value& v) noexcept { +inline const bool isNull(const value& v) noexcept { return type(v) == value::Nil; } @@ -546,7 +546,7 @@ inline const bool isPtr(const value& v) noexcept { * Returns true if a value is a tagged list. */ inline const bool isTaggedList(const value& exp, const value& tag) noexcept { - if(isList(exp) && !isNil((list<value>)exp)) + if(isList(exp) && !isNull((list<value>)exp)) return car((list<value>)exp) == tag; return false; } @@ -555,14 +555,14 @@ inline const bool isTaggedList(const value& exp, const value& tag) noexcept { * Returns true if a value is an assoc. */ inline const bool isAssoc(const value& exp) noexcept { - return isList(exp) && !isNil((list<value>)exp) && isSymbol(car<value>(exp)); + return isList(exp) && !isNull((list<value>)exp) && isSymbol(car<value>(exp)); } /** * Make a list of values from a list of other things. */ template<typename T> inline const list<value> mkvalues(const list<T>& l) noexcept { - if (isNil(l)) + if (isNull(l)) return nilListValue; return cons<value>(car(l), mkvalues(cdr(l))); } @@ -571,7 +571,7 @@ template<typename T> inline const list<value> mkvalues(const list<T>& l) noexcep * Convert a list of values to a list of other things. */ template<typename T> inline const list<T> convertValues(const list<value>& l) noexcept { - if (isNil(l)) + if (isNull(l)) return list<T>(); return cons<T>(car(l), convertValues<T>(cdr(l))); } @@ -580,7 +580,7 @@ template<typename T> inline const list<T> convertValues(const list<value>& l) no * Convert a list of lists of values to a list of values. */ inline const list<value> listOfValues(const list<list<value> >& l) noexcept { - if (isNil(l)) + if (isNull(l)) return nilListValue; return cons<value>(car(l), listOfValues(cdr(l))); } @@ -589,7 +589,7 @@ inline const list<value> listOfValues(const list<list<value> >& l) noexcept { * Convert a list of values to a list of lists of values. */ inline const list<list<value> > listOfListOfValues(const list<value>& l) noexcept { - if (isNil(l)) + if (isNull(l)) return list<list<value> >(); return cons<list<value> >(type(car(l)) == value::List? list<value>(car(l)) : nilPairValue, listOfListOfValues(cdr(l))); } @@ -613,7 +613,7 @@ inline const list<value> pathValues(const value& p) noexcept { * Convert a path represented as a list of values to a string value. */ inline const value path(const list<value>& p) noexcept { - if (isNil(p)) + if (isNull(p)) return emptyString; return string("/") + (string)car(p) + (string)path(cdr(p)); } |