From cd7dae28b034deebc9c2c2469ed9d8f1f3dab1ed Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 30 Nov 2009 08:36:07 +0000 Subject: Added debug macros and cleaned up debug logging. Added locking macros used when compiling for multithreading. Fixed value conversions to numbers. Fixed compile warnings. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@885348 13f79535-47bb-0310-9956-ffa450edef68 --- sca-cpp/trunk/modules/eval/io.hpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'sca-cpp/trunk/modules/eval/io.hpp') diff --git a/sca-cpp/trunk/modules/eval/io.hpp b/sca-cpp/trunk/modules/eval/io.hpp index a898a11440..53657ce055 100644 --- a/sca-cpp/trunk/modules/eval/io.hpp +++ b/sca-cpp/trunk/modules/eval/io.hpp @@ -77,14 +77,14 @@ const char readChar(std::istream& in) { if(in.eof()) { return -1; } - char c = in.get(); + char c = (char)in.get(); return c; } const char peekChar(std::istream& in) { if(in.eof()) return -1; - char c = in.peek(); + char c = (char)in.peek(); return c; } @@ -95,7 +95,7 @@ const bool isQuote(const value& token) { const value skipComment(std::istream& in); const value readQuoted(std::istream& in); const value readIdentifier(const char chr, std::istream& in); -const value readString(const char chr, std::istream& in); +const value readString(std::istream& in); const value readNumber(const char chr, std::istream& in); const value readValue(std::istream& in); @@ -112,14 +112,14 @@ const value readToken(std::istream& in) { if(firstChar == ')') return rightParenthesis; if(firstChar == '"') - return readString(firstChar, in); + return readString(in); if(isIdentifierStart(firstChar)) return readIdentifier(firstChar, in); if(isDigit(firstChar)) return readNumber(firstChar, in); if(firstChar == -1) return value(); - std::cout << "Illegal lexical syntax '" << firstChar << "'" << "\n"; + logStream() << "Illegal lexical syntax '" << firstChar << "'" << std::endl; return readToken(in); } @@ -167,7 +167,7 @@ const list readStringHelper(const list& listSoFar, std::istream& in) return reverse(listSoFar); } -const value readString(const char chr, std::istream& in) { +const value readString(std::istream& in) { return listToString(readStringHelper(list(), in)); } @@ -189,11 +189,25 @@ const value readValue(std::istream& in) { return nextToken; } +const value readValue(const std::string s) { + std::istringstream in(s); + const value nextToken = readToken(in); + if(isLeftParenthesis(nextToken)) + return readList(list (), in); + return nextToken; +} + const bool writeValue(const value& val, std::ostream& out) { out << val; return true; } +const std::string writeValue(const value& val) { + std::ostringstream out; + out << val; + return out.str(); +} + const value readScript(std::istream& in) { const value val = readValue(in); if (isNil(val)) -- cgit v1.2.3