summaryrefslogtreecommitdiffstats
path: root/cpp/sca
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-10-03 21:50:43 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2009-10-03 21:50:43 +0000
commit9d50a5f28dea714aca1e0941db4a2f87d40eb99c (patch)
tree0c69b53fda98bf2b4174f5576b510a91442e8ed5 /cpp/sca
parent3dfdf5ef0405474dbd4084e1aafdc44d9b1d49e4 (diff)
Minor code cleanup.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@821427 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp/sca')
-rw-r--r--cpp/sca/kernel/kernel-test.cpp8
-rw-r--r--cpp/sca/kernel/value.hpp6
-rw-r--r--cpp/sca/kernel/xml.hpp38
-rw-r--r--cpp/sca/modules/eval/driver.hpp3
-rw-r--r--cpp/sca/modules/eval/eval-test.cpp12
5 files changed, 33 insertions, 34 deletions
diff --git a/cpp/sca/kernel/kernel-test.cpp b/cpp/sca/kernel/kernel-test.cpp
index fb3f540abd..7eaa6a6354 100644
--- a/cpp/sca/kernel/kernel-test.cpp
+++ b/cpp/sca/kernel/kernel-test.cpp
@@ -232,8 +232,8 @@ bool testSeq() {
list<double> s = seq(0.0, 1000.0);
assert(1001 == length(s));
- printLambdaCounters();
- printListCounters();
+ //printLambdaCounters();
+ //printListCounters();
assert(1001 == length(map(lambda<double(double)>(testSeqMap), s)));
@@ -241,8 +241,8 @@ bool testSeq() {
assert(201 == length(member(200.0, reverse(s))));
assert(1001 == reduce(lambda<double(double, double)>(testSeqReduce), 0.0, s));
- printLambdaCounters();
- printListCounters();
+ //printLambdaCounters();
+ //printListCounters();
return true;
}
diff --git a/cpp/sca/kernel/value.hpp b/cpp/sca/kernel/value.hpp
index 184773baec..cf356b8a24 100644
--- a/cpp/sca/kernel/value.hpp
+++ b/cpp/sca/kernel/value.hpp
@@ -281,7 +281,7 @@ std::ostream& operator<<(std::ostream& out, const value& v) {
case value::Symbol:
return out << "Symbol::" << v.str()();
case value::String:
- return out << "String::" << '\'' << v.str()() << '\'';
+ return out << "String::" << '\"' << v.str()() << '\"';
case value::Number:
return out << "Number::" << v.num()();
case value::Boolean:
@@ -296,6 +296,10 @@ std::ostream& operator<<(std::ostream& out, const value& v) {
}
}
+const value::ValueType type(const value& v) {
+ return v.type;
+}
+
const bool isNil(const value& value) {
return value.type == value::Undefined;
}
diff --git a/cpp/sca/kernel/xml.hpp b/cpp/sca/kernel/xml.hpp
index 0065b23268..7ddfd6bc44 100644
--- a/cpp/sca/kernel/xml.hpp
+++ b/cpp/sca/kernel/xml.hpp
@@ -40,18 +40,18 @@ namespace tuscany {
/**
* Encapsulates a libxml2 xmlTextReader and its state.
*/
-class XmlReader {
+class XMLReader {
public:
enum TokenType {
None = 0, Element = 1, Attribute = 2, EndElement = 15, Identifier = 100, Text = 101, End = 103
};
- XmlReader(xmlTextReaderPtr xml) : xml(xml), tokenType(None) {
+ XMLReader(xmlTextReaderPtr xml) : xml(xml), tokenType(None) {
xmlTextReaderSetParserProp(xml, XML_PARSER_DEFAULTATTRS, 1);
xmlTextReaderSetParserProp(xml, XML_PARSER_SUBST_ENTITIES, 1);
}
- ~XmlReader() {
+ ~XMLReader() {
xmlFreeTextReader(xml);
}
@@ -103,7 +103,7 @@ const value element("element");
/**
* Read an XML identifier.
*/
-const value readIdentifier(XmlReader& reader) {
+const value readIdentifier(XMLReader& reader) {
const char* name = (const char*)xmlTextReaderConstName(reader);
return value(name);
}
@@ -111,7 +111,7 @@ const value readIdentifier(XmlReader& reader) {
/**
* Read XML text.
*/
-const value readText(XmlReader& reader) {
+const value readText(XMLReader& reader) {
const char *val = (const char*)xmlTextReaderConstValue(reader);
return value(std::string(val));
}
@@ -119,7 +119,7 @@ const value readText(XmlReader& reader) {
/**
* Read an XML attribute.
*/
-const value readAttribute(XmlReader& reader) {
+const value readAttribute(XMLReader& reader) {
const char *name = (const char*)xmlTextReaderConstName(reader);
const char *val = (const char*)xmlTextReaderConstValue(reader);
return value(makeList(attribute, value(name), value(std::string(val))));
@@ -128,19 +128,19 @@ const value readAttribute(XmlReader& reader) {
/**
* Read an XML token.
*/
-const value readToken(XmlReader& reader) {
+const value readToken(XMLReader& reader) {
const int tokenType = reader.read();
- if (tokenType == XmlReader::End)
+ if (tokenType == XMLReader::End)
return value();
- if (tokenType == XmlReader::Element)
+ if (tokenType == XMLReader::Element)
return startElement;
- if (tokenType == XmlReader::Identifier)
+ if (tokenType == XMLReader::Identifier)
return readIdentifier(reader);
- if (tokenType == XmlReader::Attribute)
+ if (tokenType == XMLReader::Attribute)
return readAttribute(reader);
- if (tokenType == XmlReader::Text)
+ if (tokenType == XMLReader::Text)
return readText(reader);
- if (tokenType == XmlReader::EndElement)
+ if (tokenType == XMLReader::EndElement)
return endElement;
return readToken(reader);
}
@@ -148,7 +148,7 @@ const value readToken(XmlReader& reader) {
/**
* Read a list of XML tokens.
*/
-const list<value> readList(const list<value>& listSoFar, XmlReader& reader) {
+const list<value> readList(const list<value>& listSoFar, XMLReader& reader) {
const value token = readToken(reader);
if(isNil(token) || endElement == token)
return reverse(listSoFar);
@@ -160,7 +160,7 @@ const list<value> readList(const list<value>& listSoFar, XmlReader& reader) {
/**
* Read an XML document from a libxml2 XML reader.
*/
-const list<value> read(XmlReader& reader) {
+const list<value> read(XMLReader& reader) {
value nextToken = readToken(reader);
if (startElement == nextToken)
return makeList(value(readList(makeList(element), reader)));
@@ -173,8 +173,6 @@ const list<value> read(XmlReader& reader) {
int readCallback(void *context, char* buffer, int len) {
std::istream* is = static_cast<std::istream*>(context);
is->read(buffer, len);
- if (!is->eof() && (is->fail() || is->bad()))
- return -1;
const int n = is->gcount();
return n;
}
@@ -186,7 +184,7 @@ const list<value> readXML(std::istream& is) {
xmlTextReaderPtr xml = xmlReaderForIO(readCallback, NULL, &is, NULL, NULL, XML_PARSE_NONET);
if (xml == NULL)
return list<value>();
- XmlReader reader(xml);
+ XMLReader reader(xml);
return read(reader);
}
@@ -196,8 +194,6 @@ const list<value> readXML(std::istream& is) {
int readFileCallback(void *context, char* buffer, int len) {
std::ifstream* is = static_cast<std::ifstream*>(context);
is->read(buffer, len);
- if (is->fail() || is->bad())
- return -1;
return is->gcount();
}
@@ -217,7 +213,7 @@ const list<value> readXML(std::ifstream& is) {
xmlTextReaderPtr xml = xmlReaderForIO(readFileCallback, readCloseFileCallback, &is, NULL, NULL, XML_PARSE_NONET);
if (xml == NULL)
return list<value>();
- XmlReader reader(xml);
+ XMLReader reader(xml);
return read(reader);
}
diff --git a/cpp/sca/modules/eval/driver.hpp b/cpp/sca/modules/eval/driver.hpp
index c45a6a1a6d..398fc9616d 100644
--- a/cpp/sca/modules/eval/driver.hpp
+++ b/cpp/sca/modules/eval/driver.hpp
@@ -30,8 +30,7 @@
#include <iostream>
#include "eval.hpp"
-namespace tuscany
-{
+namespace tuscany {
const std::string evalOutputPrompt("; ");
const std::string evalInputPrompt("=> ");
diff --git a/cpp/sca/modules/eval/eval-test.cpp b/cpp/sca/modules/eval/eval-test.cpp
index 81f03f1c5e..725f1b43fa 100644
--- a/cpp/sca/modules/eval/eval-test.cpp
+++ b/cpp/sca/modules/eval/eval-test.cpp
@@ -48,9 +48,9 @@ bool testEnvGC() {
assert(countValues == 0);
assert(countLambdas == 0);
assert(countlists == 0);
- printLambdaCounters();
- printListCounters();
- printValueCounters();
+ //printLambdaCounters();
+ //printListCounters();
+ //printValueCounters();
return true;
}
@@ -148,9 +148,9 @@ bool testEvalGC() {
assert(countValues == 0);
assert(countLambdas == 0);
assert(countlists == 0);
- printLambdaCounters();
- printListCounters();
- printValueCounters();
+ //printLambdaCounters();
+ //printListCounters();
+ //printValueCounters();
return true;
}