From 7659ef059fa31c780f7c4e0fb028b9fb5b400030 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Mon, 30 Jan 2017 15:30:55 +0100 Subject: Unified DOM traversal and removed iostreams --- apps/uscxml-browser.cpp | 8 +- src/bindings/swig/wrapped/WrappedActionLanguage.h | 1 - src/bindings/swig/wrapped/WrappedDataModel.h | 1 - src/uscxml/Interpreter.cpp | 31 ++-- src/uscxml/debug/DebugSession.cpp | 2 +- src/uscxml/debug/DebuggerServlet.cpp | 8 +- src/uscxml/debug/InterpreterIssue.cpp | 4 +- src/uscxml/debug/InterpreterIssue.h | 1 - src/uscxml/interpreter/BasicContentExecutor.cpp | 4 +- src/uscxml/interpreter/InterpreterImpl.cpp | 1 - src/uscxml/interpreter/InterpreterMonitor.h | 8 +- src/uscxml/interpreter/Logging.cpp | 2 + src/uscxml/interpreter/Logging.h | 2 + src/uscxml/interpreter/StdOutLogger.cpp | 6 +- src/uscxml/plugins/Factory.cpp | 29 ++- .../ecmascript/JavaScriptCore/JSCDataModel.cpp | 2 +- .../datamodel/ecmascript/v8/V8DataModel.cpp | 4 +- .../plugins/datamodel/promela/PromelaParser.cpp | 14 +- .../ioprocessor/basichttp/BasicHTTPIOProcessor.cpp | 1 - src/uscxml/server/HTTPServer.cpp | 1 - src/uscxml/transform/ChartToC.cpp | 3 +- src/uscxml/transform/ChartToPromela.cpp | 2 +- src/uscxml/transform/ChartToVHDL.cpp | 1 - src/uscxml/transform/Transformer.h | 1 - src/uscxml/transform/Trie.cpp | 4 +- src/uscxml/transform/Trie.h | 4 +- src/uscxml/transform/promela/PromelaInlines.cpp | 6 +- src/uscxml/util/DOM.cpp | 205 +++------------------ src/uscxml/util/DOM.h | 48 ++--- src/uscxml/util/MD5.hpp | 1 - src/uscxml/util/SHA1.hpp | 1 - test/src/test-extensions.cpp | 1 + test/src/test-gen-c.cpp | 2 + test/src/test-lifecycle.cpp | 2 +- test/src/test-utils.cpp | 2 + test/src/test-validating.cpp | 1 + 36 files changed, 132 insertions(+), 282 deletions(-) diff --git a/apps/uscxml-browser.cpp b/apps/uscxml-browser.cpp index 626ad60..cf6e874 100644 --- a/apps/uscxml-browser.cpp +++ b/apps/uscxml-browser.cpp @@ -66,10 +66,10 @@ int main(int argc, char** argv) { if (options.validate) { std::list issues = interpreter.validate(); for (std::list::iterator issueIter = issues.begin(); issueIter != issues.end(); issueIter++) { - std::cout << *issueIter << std::endl; + LOGD(USCXML_DEBUG) << "" << *issueIter << std::endl; } if (issues.size() == 0) { - std::cout << "No issues found" << std::endl; + LOGD(USCXML_DEBUG) << "No issues found" << std::endl; } } @@ -86,7 +86,7 @@ int main(int argc, char** argv) { LOGD(USCXML_ERROR) << "Cannot create interpreter from " << documentURL; } } catch (Event e) { - std::cout << e << std::endl; + LOGD(USCXML_DEBUG) << e << std::endl; } } @@ -116,7 +116,7 @@ int main(int argc, char** argv) { interpreterIter = interpreters.begin(); } } catch (Event e) { - std::cout << e << std::endl; + LOGD(USCXML_ERROR) << e << std::endl; } } else if (options.withDebugger) { while(true) diff --git a/src/bindings/swig/wrapped/WrappedActionLanguage.h b/src/bindings/swig/wrapped/WrappedActionLanguage.h index 55e009c..a34be52 100644 --- a/src/bindings/swig/wrapped/WrappedActionLanguage.h +++ b/src/bindings/swig/wrapped/WrappedActionLanguage.h @@ -24,7 +24,6 @@ #include #include #include -#include #include diff --git a/src/bindings/swig/wrapped/WrappedDataModel.h b/src/bindings/swig/wrapped/WrappedDataModel.h index de0c4a9..e0bd422 100644 --- a/src/bindings/swig/wrapped/WrappedDataModel.h +++ b/src/bindings/swig/wrapped/WrappedDataModel.h @@ -24,7 +24,6 @@ #include #include #include -#include #include diff --git a/src/uscxml/Interpreter.cpp b/src/uscxml/Interpreter.cpp index 4630cf2..2c6e80d 100644 --- a/src/uscxml/Interpreter.cpp +++ b/src/uscxml/Interpreter.cpp @@ -32,7 +32,6 @@ #include #include "uscxml/interpreter/Logging.h" -#include #include #include @@ -256,10 +255,10 @@ std::list Interpreter::validate() { } #if 1 -static void printNodeSet(const std::list nodes) { +static void printNodeSet(Logger& logger, const std::list nodes) { std::string seperator; for (auto nIter = nodes.begin(); nIter != nodes.end(); nIter++) { - std::cerr << seperator << (HAS_ATTR(*nIter, "id") ? ATTR(*nIter, "id") : DOMUtils::xPathForNode(*nIter)); + LOG(logger, USCXML_VERBATIM) << seperator << (HAS_ATTR(*nIter, "id") ? ATTR(*nIter, "id") : DOMUtils::xPathForNode(*nIter)); seperator = ", "; } } @@ -269,52 +268,52 @@ std::recursive_mutex StateTransitionMonitor::_mutex; void StateTransitionMonitor::beforeTakingTransition(Interpreter& interpreter, const XERCESC_NS::DOMElement* transition) { std::lock_guard lock(_mutex); - std::cerr << "Transition: " << uscxml::DOMUtils::xPathForNode(transition) << std::endl; + LOG(_logger, USCXML_VERBATIM) << "Transition: " << uscxml::DOMUtils::xPathForNode(transition) << std::endl; } void StateTransitionMonitor::onStableConfiguration(Interpreter& interpreter) { std::lock_guard lock(_mutex); - std::cerr << "Stable Config: { "; - printNodeSet(interpreter.getConfiguration()); - std::cerr << " }" << std::endl; + LOG(_logger, USCXML_VERBATIM) << "Stable Config: { "; + printNodeSet(_logger, interpreter.getConfiguration()); + LOG(_logger, USCXML_VERBATIM) << " }" << std::endl; } void StateTransitionMonitor::beforeProcessingEvent(Interpreter& interpreter, const uscxml::Event& event) { std::lock_guard lock(_mutex); switch (event.eventType) { case uscxml::Event::INTERNAL: - std::cerr << "Internal Event: " << event.name << std::endl; + LOG(_logger, USCXML_VERBATIM) << "Internal Event: " << event.name << std::endl; break; case uscxml::Event::EXTERNAL: - std::cerr << "External Event: " << event.name << std::endl; + LOG(_logger, USCXML_VERBATIM) << "External Event: " << event.name << std::endl; break; case uscxml::Event::PLATFORM: - std::cerr << "Platform Event: " << event.name << std::endl; + LOG(_logger, USCXML_VERBATIM) << "Platform Event: " << event.name << std::endl; break; } } void StateTransitionMonitor::beforeExecutingContent(Interpreter& interpreter, const XERCESC_NS::DOMElement* element) { std::lock_guard lock(_mutex); - std::cerr << "Executable Content: " << DOMUtils::xPathForNode(element) << std::endl; + LOG(_logger, USCXML_VERBATIM) << "Executable Content: " << DOMUtils::xPathForNode(element) << std::endl; } void StateTransitionMonitor::beforeExitingState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) { std::lock_guard lock(_mutex); - std::cerr << "Exiting: " << (HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::xPathForNode(state)) << std::endl; + LOG(_logger, USCXML_VERBATIM) << "Exiting: " << (HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::xPathForNode(state)) << std::endl; } void StateTransitionMonitor::beforeEnteringState(Interpreter& interpreter, const XERCESC_NS::DOMElement* state) { std::lock_guard lock(_mutex); - std::cerr << "Entering: " << (HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::xPathForNode(state)) << std::endl; + LOG(_logger, USCXML_VERBATIM) << "Entering: " << (HAS_ATTR(state, "id") ? ATTR(state, "id") : DOMUtils::xPathForNode(state)) << std::endl; } void StateTransitionMonitor::beforeMicroStep(Interpreter& interpreter) { std::lock_guard lock(_mutex); - std::cerr << "Microstep in config: {"; - printNodeSet(interpreter.getConfiguration()); - std::cerr << "}" << std::endl; + LOG(_logger, USCXML_VERBATIM) << "Microstep in config: {"; + printNodeSet(_logger, interpreter.getConfiguration()); + LOG(_logger, USCXML_VERBATIM) << "}" << std::endl; } } diff --git a/src/uscxml/debug/DebugSession.cpp b/src/uscxml/debug/DebugSession.cpp index f6b3ae1..0b939d9 100644 --- a/src/uscxml/debug/DebugSession.cpp +++ b/src/uscxml/debug/DebugSession.cpp @@ -113,7 +113,7 @@ Data DebugSession::debugPrepare(const Data& data) { _interpreter = Interpreter(); } } catch(ErrorEvent e) { - std::cerr << e; + log(USCXML_ERROR, e); } catch(...) {} if (_interpreter) { diff --git a/src/uscxml/debug/DebuggerServlet.cpp b/src/uscxml/debug/DebuggerServlet.cpp index 44255c0..c3d0f9f 100644 --- a/src/uscxml/debug/DebuggerServlet.cpp +++ b/src/uscxml/debug/DebuggerServlet.cpp @@ -25,7 +25,7 @@ namespace uscxml { void DebuggerServlet::pushData(std::shared_ptr session, Data pushData) { - std::cout << "trying to push " << pushData.at("replyType").atom << std::endl; + LOGD(USCXML_DEBUG) << "trying to push " << pushData.at("replyType").atom << std::endl; if (!session) { if (_sendQueues.size() > 0) // logging is not aware of its interpreter @@ -45,7 +45,7 @@ void DebuggerServlet::serverPushData(std::shared_ptr session) { return; Data reply = _sendQueues[session].pop(); - std::cout << "pushing " << reply.at("replyType").atom << std::endl; + LOGD(USCXML_DEBUG) << "pushing " << reply.at("replyType").atom << std::endl; returnData(_clientConns[session], reply); _clientConns[session] = HTTPServer::Request(); } @@ -57,7 +57,7 @@ void DebuggerServlet::returnData(const HTTPServer::Request& request, Data replyD replyData.compound["status"] = Data("success", Data::VERBATIM); } - std::cout << "<- " << replyData << std::endl; + LOGD(USCXML_DEBUG) << "<- " << replyData << std::endl; reply.content = Data::toJSON(replyData); reply.headers["Access-Control-Allow-Origin"] = "*"; @@ -96,7 +96,7 @@ bool DebuggerServlet::requestFromHTTP(const HTTPServer::Request& request) { return true; } - std::cout << request.data["path"] << ": " << request.data["content"] << std::endl; + LOGD(USCXML_DEBUG) << request.data["path"] << ": " << request.data["content"] << std::endl; Data replyData; // process request that don't need a session diff --git a/src/uscxml/debug/InterpreterIssue.cpp b/src/uscxml/debug/InterpreterIssue.cpp index 4ee4442..4f2e31f 100644 --- a/src/uscxml/debug/InterpreterIssue.cpp +++ b/src/uscxml/debug/InterpreterIssue.cpp @@ -55,10 +55,10 @@ std::list > getAllConfigurations(const DOMElement* std::string localName = X(root->getLocalName()); bool isAtomic = true; - std::cout << *root; +// std::cout << *root; for (auto childElem = root->getFirstElementChild(); childElem; childElem = childElem->getNextElementSibling()) { - std::cout << *childElem; +// std::cout << *childElem; if (XMLString::compareIString(childElem->getTagName(), X(nsPrefix + "state")) == 0 || XMLString::compareIString(childElem->getTagName(), X(nsPrefix + "parallel")) == 0 || diff --git a/src/uscxml/debug/InterpreterIssue.h b/src/uscxml/debug/InterpreterIssue.h index 983c1ad..d845ba8 100644 --- a/src/uscxml/debug/InterpreterIssue.h +++ b/src/uscxml/debug/InterpreterIssue.h @@ -24,7 +24,6 @@ #include "uscxml/Common.h" #include -#include // forward declare namespace XERCESC_NS { diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 192e714..b57837f 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -277,9 +277,9 @@ void BasicContentExecutor::processLog(XERCESC_NS::DOMElement* content) { Data d = _callbacks->evalAsData(expr); if (label.size() > 0) { - std::cout << label << ": "; + _callbacks->getLogger().log(USCXML_LOG) << label << ": "; } - std::cout << d << std::endl; + _callbacks->getLogger().log(USCXML_LOG) << d << std::endl; } void BasicContentExecutor::processScript(XERCESC_NS::DOMElement* content) { diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp index 33a1169..812c73b 100644 --- a/src/uscxml/interpreter/InterpreterImpl.cpp +++ b/src/uscxml/interpreter/InterpreterImpl.cpp @@ -32,7 +32,6 @@ #include "uscxml/interpreter/Logging.h" -#include #include #include diff --git a/src/uscxml/interpreter/InterpreterMonitor.h b/src/uscxml/interpreter/InterpreterMonitor.h index 7207558..27222b4 100644 --- a/src/uscxml/interpreter/InterpreterMonitor.h +++ b/src/uscxml/interpreter/InterpreterMonitor.h @@ -22,6 +22,7 @@ #include "uscxml/Common.h" #include "uscxml/messages/Event.h" +#include "uscxml/interpreter/Logging.h" #include "uscxml/debug/InterpreterIssue.h" #include @@ -55,7 +56,10 @@ class Interpreter; class USCXML_API InterpreterMonitor { public: - InterpreterMonitor() : _copyToInvokers(false) {} + InterpreterMonitor() : _copyToInvokers(false) { + _logger = Logger::getDefault(); + } + InterpreterMonitor(Logger logger) : _copyToInvokers(false), _logger(logger) {} virtual ~InterpreterMonitor() {} virtual void beforeProcessingEvent(Interpreter& interpreter, const Event& event) {} @@ -97,7 +101,7 @@ public: protected: bool _copyToInvokers; - + Logger _logger; }; class USCXML_API StateTransitionMonitor : public uscxml::InterpreterMonitor { diff --git a/src/uscxml/interpreter/Logging.cpp b/src/uscxml/interpreter/Logging.cpp index 70c29de..0b3caac 100644 --- a/src/uscxml/interpreter/Logging.cpp +++ b/src/uscxml/interpreter/Logging.cpp @@ -90,6 +90,8 @@ std::string Logger::severityToString(LogSeverity severity) { return "Error"; case USCXML_FATAL: return "Fatal"; + case USCXML_LOG: + return "Log"; default: return "Unknown"; diff --git a/src/uscxml/interpreter/Logging.h b/src/uscxml/interpreter/Logging.h index b139211..348e9dc 100644 --- a/src/uscxml/interpreter/Logging.h +++ b/src/uscxml/interpreter/Logging.h @@ -38,6 +38,8 @@ enum LogSeverity { USCXML_TRACE, USCXML_DEBUG, USCXML_INFO, + USCXML_LOG, // from log element + USCXML_VERBATIM, // no additional decorations USCXML_WARN, USCXML_ERROR, USCXML_FATAL diff --git a/src/uscxml/interpreter/StdOutLogger.cpp b/src/uscxml/interpreter/StdOutLogger.cpp index 2cbe4c7..3f954d6 100644 --- a/src/uscxml/interpreter/StdOutLogger.cpp +++ b/src/uscxml/interpreter/StdOutLogger.cpp @@ -27,15 +27,15 @@ std::shared_ptr StdOutLogger::create() { } void StdOutLogger::log(LogSeverity severity, const std::string& message) { - std::cout << Logger::severityToString(severity) << ": " << message << std::endl; + std::cout << (severity != USCXML_VERBATIM ? Logger::severityToString(severity) + ": " : "") << message << std::endl; } void StdOutLogger::log(LogSeverity severity, const Event& event) { - std::cout << Logger::severityToString(severity) << ": " << event << std::endl; + std::cout << (severity != USCXML_VERBATIM ? Logger::severityToString(severity) + ": " : "") << event << std::endl; } void StdOutLogger::log(LogSeverity severity, const Data& data) { - std::cout << Logger::severityToString(severity) << ": " << data << std::endl; + std::cout << (severity != USCXML_VERBATIM ? Logger::severityToString(severity) + ": " : "") << data << std::endl; } } diff --git a/src/uscxml/plugins/Factory.cpp b/src/uscxml/plugins/Factory.cpp index 0b9104e..5b767b6 100644 --- a/src/uscxml/plugins/Factory.cpp +++ b/src/uscxml/plugins/Factory.cpp @@ -37,7 +37,6 @@ #include #include "uscxml/util/DOM.h" -#include // see http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system @@ -246,19 +245,19 @@ while(iter != name.end()) { \ std::list names = iter->second->getNames(); \ std::list::iterator nameIter = names.begin(); \ if (nameIter != names.end()) { \ - std::cout << "\t" << *nameIter; \ + LOGD(USCXML_VERBATIM) << "\t" << *nameIter; \ nameIter++; \ std::string seperator = ""; \ if (nameIter != names.end()) { \ - std::cout << "\t("; \ + LOGD(USCXML_VERBATIM) << "\t("; \ while(nameIter != names.end()) { \ - std::cout << seperator << *nameIter; \ + LOGD(USCXML_VERBATIM) << seperator << *nameIter; \ seperator = ", "; \ nameIter++; \ } \ - std::cout << ")"; \ + LOGD(USCXML_VERBATIM) << ")"; \ } \ - std::cout << std::endl; \ + LOGD(USCXML_VERBATIM) << "\n"; \ } \ iter++; \ } @@ -266,28 +265,28 @@ while(iter != name.end()) { \ void Factory::listComponents() { { - std::cout << "Available Datamodels:" << std::endl; + LOGD(USCXML_VERBATIM) << "Available Datamodels:" << std::endl; LIST_COMPONENTS(DataModelImpl, _dataModels); - std::cout << std::endl; + LOGD(USCXML_VERBATIM) << "\n"; } { - std::cout << "Available Invokers:" << std::endl; + LOGD(USCXML_VERBATIM) << "Available Invokers:" << std::endl; LIST_COMPONENTS(InvokerImpl, _invokers); - std::cout << std::endl; + LOGD(USCXML_VERBATIM) << "\n"; } { - std::cout << "Available I/O Processors:" << std::endl; + LOGD(USCXML_VERBATIM) << "Available I/O Processors:" << std::endl; LIST_COMPONENTS(IOProcessorImpl, _ioProcessors); - std::cout << std::endl; + LOGD(USCXML_VERBATIM) << "\n"; } { - std::cout << "Available Elements:" << std::endl; + LOGD(USCXML_VERBATIM) << "Available Elements:" << std::endl; std::map, ExecutableContentImpl*>::iterator iter = _executableContent.begin(); while(iter != _executableContent.end()) { - std::cout << "\t" << iter->second->getNamespace() << " / " << iter->second->getLocalName() << std::endl; + LOGD(USCXML_VERBATIM) << "\t" << iter->second->getNamespace() << " / " << iter->second->getLocalName() << std::endl; iter++; } - std::cout << std::endl; + LOGD(USCXML_VERBATIM) << "\n"; } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 66bf45a..2a1ebab 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -769,7 +769,7 @@ JSValueRef JSCDataModel::jsPrint(JSContextRef ctx, JSObjectRef function, JSObjec std::string msg(buffer); free(buffer); - std::cout << msg; + INSTANCE->_callbacks->getLogger().log(USCXML_LOG) << msg; } } return JSValueMakeUndefined(ctx); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 84cfa81..9eaa8c5 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -624,7 +624,9 @@ v8::Local V8DataModel::getDataAsValue(const Data& data) { void V8DataModel::jsPrint(const v8::FunctionCallbackInfo& info) { if (info.Length() > 0) { v8::String::AsciiValue printMsg(info[0]->ToString()); - std::cout << *printMsg; + v8::Local field = v8::Local::Cast(info.Data()); + V8DataModel* dataModel = (V8DataModel*)field->Value(); + dataModel->_callbacks->getLogger().log(USCXML_LOG) << *printMsg; } } diff --git a/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp b/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp index 44f8bdd..e2b8819 100644 --- a/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp +++ b/src/uscxml/plugins/datamodel/promela/PromelaParser.cpp @@ -20,8 +20,8 @@ #include "PromelaParser.h" #include "parser/promela.tab.hpp" #include "uscxml/messages/Event.h" +#include "uscxml/interpreter/Logging.h" -#include #include // memcpy struct yy_buffer_state; @@ -169,13 +169,13 @@ PromelaParserNode* PromelaParser::value(int type, void* location, const char* va void PromelaParser::dump() { switch (type) { case PROMELA_EXPR: - std::cout << "Promela Expression" << std::endl; + LOGD(USCXML_VERBATIM) << "Promela Expression" << std::endl; break; case PROMELA_DECL: - std::cout << "Promela Declarations" << std::endl; + LOGD(USCXML_VERBATIM) << "Promela Declarations" << std::endl; break; case PROMELA_STMNT: - std::cout << "Promela Statement" << std::endl; + LOGD(USCXML_VERBATIM) << "Promela Statement" << std::endl; break; } ast->dump(); @@ -201,11 +201,11 @@ void PromelaParserNode::dump(size_t indent) { for (size_t i = 0; i < indent; i++) { padding += " "; } - std::cout << padding << typeToDesc(type) << ": " << value; + LOGD(USCXML_VERBATIM) << padding << typeToDesc(type) << ": " << value; if (loc != NULL) { - std::cout << " (" << loc->firstLine << ":" << loc->firstCol << ")-(" << loc->lastLine << ":" << loc->lastCol << ")"; + LOGD(USCXML_VERBATIM) << " (" << loc->firstLine << ":" << loc->firstCol << ")-(" << loc->lastLine << ":" << loc->lastCol << ")"; } - std::cout << std::endl; + LOGD(USCXML_VERBATIM) << "\n"; for (std::list::iterator iter = operands.begin(); iter != operands.end(); iter++) { (*iter)->dump(indent + 1); diff --git a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp index cc0c9d4..2f8f0aa 100644 --- a/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp +++ b/src/uscxml/plugins/ioprocessor/basichttp/BasicHTTPIOProcessor.cpp @@ -23,7 +23,6 @@ #include "uscxml/messages/Event.h" #include "uscxml/util/DOM.h" -#include #include #include #include diff --git a/src/uscxml/server/HTTPServer.cpp b/src/uscxml/server/HTTPServer.cpp index ab16887..66c9a43 100644 --- a/src/uscxml/server/HTTPServer.cpp +++ b/src/uscxml/server/HTTPServer.cpp @@ -29,7 +29,6 @@ #include "uscxml/util/DOM.h" #include -#include extern "C" { #include diff --git a/src/uscxml/transform/ChartToC.cpp b/src/uscxml/transform/ChartToC.cpp index 7deef17..4cdb3ef 100644 --- a/src/uscxml/transform/ChartToC.cpp +++ b/src/uscxml/transform/ChartToC.cpp @@ -18,7 +18,6 @@ */ #include "uscxml/transform/ChartToC.h" -#include #include "uscxml/util/UUID.h" #include "uscxml/util/Predicates.h" #include "uscxml/util/MD5.hpp" @@ -1358,7 +1357,7 @@ void ChartToC::writeExecContent(std::ostream& stream, const DOMNode* node, size_ stream << padding << "}" << std::endl; } else { - std::cerr << "'" << TAGNAME(elem) << "'" << std::endl << elem << std::endl; + LOGD(USCXML_VERBATIM) << "'" << TAGNAME(elem) << "'" << std::endl << elem << std::endl; assert(false); } diff --git a/src/uscxml/transform/ChartToPromela.cpp b/src/uscxml/transform/ChartToPromela.cpp index 7b1c327..6d77a94 100644 --- a/src/uscxml/transform/ChartToPromela.cpp +++ b/src/uscxml/transform/ChartToPromela.cpp @@ -1233,7 +1233,7 @@ void ChartToPromela::writeExecContent(std::ostream& stream, const XERCESC_NS::DO stream << " " << padding << "cancelSendId(" << ADAPT_SRC(ATTR(element, "sendidexpr")) << "," << _analyzer->macroForLiteral(_invokerid) << ");" << std::endl; } } else { - std::cerr << "'" << TAGNAME(element) << "' not supported" << std::endl << element << std::endl; + LOGD(USCXML_VERBATIM) << "'" << TAGNAME(element) << "' not supported" << std::endl << element << std::endl; assert(false); } } diff --git a/src/uscxml/transform/ChartToVHDL.cpp b/src/uscxml/transform/ChartToVHDL.cpp index 578b310..1f25bb8 100644 --- a/src/uscxml/transform/ChartToVHDL.cpp +++ b/src/uscxml/transform/ChartToVHDL.cpp @@ -26,7 +26,6 @@ #include #include "uscxml/interpreter/Logging.h" -#include #include #include diff --git a/src/uscxml/transform/Transformer.h b/src/uscxml/transform/Transformer.h index d3c60e8..fd3dbe2 100644 --- a/src/uscxml/transform/Transformer.h +++ b/src/uscxml/transform/Transformer.h @@ -20,7 +20,6 @@ #ifndef TRANSFORMER_H_32113356 #define TRANSFORMER_H_32113356 -#include #include #include "uscxml/Interpreter.h" #include "uscxml/interpreter/InterpreterImpl.h" diff --git a/src/uscxml/transform/Trie.cpp b/src/uscxml/transform/Trie.cpp index 9966931..c6ee24d 100644 --- a/src/uscxml/transform/Trie.cpp +++ b/src/uscxml/transform/Trie.cpp @@ -18,7 +18,6 @@ */ #include "Trie.h" -#include #include namespace uscxml { @@ -146,6 +145,7 @@ std::list Trie::getChildsWithWords(TrieNode* node) { return nodes; } +#if 0 void TrieNode::dump(size_t indent) { std::string padding; for (size_t i = 0; i < indent; i++) { @@ -169,5 +169,5 @@ void Trie::dump() { std::cout << "(word)" << std::endl; root->dump(); } - +#endif } diff --git a/src/uscxml/transform/Trie.h b/src/uscxml/transform/Trie.h index 2c7da8b..fd85653 100644 --- a/src/uscxml/transform/Trie.h +++ b/src/uscxml/transform/Trie.h @@ -36,7 +36,7 @@ struct USCXML_API TrieNode { std::string identifier; std::string value; std::map childs; - void dump(size_t indent = 0); +// void dump(size_t indent = 0); }; struct USCXML_API Trie { @@ -51,7 +51,7 @@ struct USCXML_API Trie { TrieNode* getNodeWithPrefix(const std::string& prefix); std::list getWordsWithPrefix(const std::string& prefix); std::list getChildsWithWords(TrieNode* node); - void dump(); +// void dump(); TrieNode* root; std::string seperator; diff --git a/src/uscxml/transform/promela/PromelaInlines.cpp b/src/uscxml/transform/promela/PromelaInlines.cpp index 7d62762..cc8a12c 100644 --- a/src/uscxml/transform/promela/PromelaInlines.cpp +++ b/src/uscxml/transform/promela/PromelaInlines.cpp @@ -18,8 +18,10 @@ */ #include "PromelaInlines.h" +#include "uscxml/interpreter/Logging.h" #include + namespace uscxml { using namespace XERCESC_NS; @@ -73,7 +75,7 @@ PromelaInline::PromelaInline(const XERCESC_NS::DOMNode* node) { while(std::getline(ssLine, line)) { boost::trim(line); if (boost::starts_with(line, "promela")) { - std::cerr << "Split multiple #promela pragmas into multiple comments!" << std::endl; + LOGD(USCXML_ERROR) << "Split multiple #promela pragmas into multiple comments!" << std::endl; break; } contentSS << seperator << line; @@ -162,4 +164,4 @@ std::list PromelaInlines::getAllOfType(uint32_t type) { } -} \ No newline at end of file +} diff --git a/src/uscxml/util/DOM.cpp b/src/uscxml/util/DOM.cpp index c21dee1..be6012b 100644 --- a/src/uscxml/util/DOM.cpp +++ b/src/uscxml/util/DOM.cpp @@ -219,6 +219,17 @@ bool DOMUtils::isDescendant(const DOMNode* s1, return false; } +std::list DOMUtils::filterElementGeneric(const std::set& elements, + const DOMElement* root, + const Order order, + const bool includeEmbeddedDoc, + const bool includeRoot) { + std::list result; + filterElementGeneric(elements, result, root, order, includeEmbeddedDoc, includeRoot); + return result; +} + + void DOMUtils::filterElementGeneric(const std::set& elements, std::list& result, const DOMElement* root, @@ -261,9 +272,19 @@ void DOMUtils::filterElementGeneric(const std::set& elements, } +std::list DOMUtils::filterTypeGeneric(const std::set& types, + const DOMNode* root, + const Order order, + const bool includeEmbeddedDoc, + const bool includeRoot) { + std::list result; + filterTypeGeneric(types, result, root, order, includeEmbeddedDoc, includeRoot); + return result; +} + void DOMUtils::filterTypeGeneric(const std::set& types, std::list& result, - const DOMElement* root, + const DOMNode* root, const Order order, const bool includeEmbeddedDoc, const bool includeRoot) { @@ -304,43 +325,7 @@ void DOMUtils::filterTypeGeneric(const std::set& types, } -#if 1 -std::list DOMUtils::inPostFixOrder(const std::set& elements, - const DOMElement* root, - const bool includeEmbeddedDoc) { - std::list result; - filterElementGeneric(elements, result, root, POSTFIX, includeEmbeddedDoc, true); - return result; -} -#else -std::list DOMUtils::inPostFixOrder(const std::set& elements, - const DOMElement* root, - const bool includeEmbeddedDoc) { - std::list nodes; - inPostFixOrder(elements, root, includeEmbeddedDoc, nodes); - return nodes; -} -#endif - -#if 1 -std::list DOMUtils::inDocumentOrder(const std::set& elements, - const DOMElement* root, - const bool includeEmbeddedDoc) { - std::list result; - filterElementGeneric(elements, result, root, DOCUMENT, includeEmbeddedDoc, true); - return result; -} -#else -std::list DOMUtils::inDocumentOrder(const std::set& elements, - const DOMElement* root, - const bool includeEmbeddedDoc) { - std::list nodes; - inDocumentOrder(elements, root, includeEmbeddedDoc, nodes); - return nodes; -} -#endif -#if 1 std::list DOMUtils::filterChildElements(const std::string& tagName, const std::list& nodeSet, bool recurse) { @@ -354,57 +339,7 @@ std::list DOMUtils::filterChildElements(const std::string& tagName, } return filteredChildElems; } -#else -std::list DOMUtils::filterChildElements(const std::string& tagName, - const std::list& nodeSet, - bool recurse) { - - std::list filteredChildElems; - std::list::const_iterator nodeIter = nodeSet.begin(); - while(nodeIter != nodeSet.end()) { - std::list filtered = filterChildElements(tagName, *nodeIter, recurse); - filteredChildElems.merge(filtered); // TODO: guess we want insert? - nodeIter++; - } - return filteredChildElems; -} -#endif - -#if 1 -std::list DOMUtils::filterChildElements(const std::string& tagName, - const DOMElement* node, - bool recurse) { - - std::list result; - filterElementGeneric({ tagName }, result, node, (recurse ? DOCUMENT : NO_RECURSE), true, false); - return result; -} -#else -std::list DOMUtils::filterChildElements(const std::string& tagName, - const DOMElement* node, - bool recurse) { - - std::list filteredChildElems; - - if (!node) - return filteredChildElems; - - for (auto childElem = node->getFirstElementChild(); childElem; childElem = childElem->getNextElementSibling()) { - // std::cerr << TAGNAME(childs.item(i)) << std::endl; - if(iequals(TAGNAME(childElem), tagName)) { - filteredChildElems.push_back((DOMElement*)childElem); - } - if (recurse) { - std::list nested = filterChildElements(tagName, childElem, recurse); - filteredChildElems.merge(nested); - } - } - return filteredChildElems; -} - -#endif -#if 1 std::list DOMUtils::filterChildType(const DOMNode::NodeType type, const std::list& nodeSet, bool recurse) { @@ -417,101 +352,5 @@ std::list DOMUtils::filterChildType(const DOMNode::NodeType type, } return filteredChildType; } -#else -std::list DOMUtils::filterChildType(const DOMNode::NodeType type, - const std::list& nodeSet, - bool recurse) { - std::list filteredChildType; - std::list::const_iterator nodeIter = nodeSet.begin(); - while(nodeIter != nodeSet.end()) { - std::list filtered = filterChildType(type, *nodeIter, recurse); - filteredChildType.merge(filtered); - nodeIter++; - } - return filteredChildType; -} -#endif - -#if 1 -std::list DOMUtils::filterChildType(const DOMNode::NodeType type, - const DOMNode* node, - bool recurse) { - - std::list result; - if (node) { - assert(node->getNodeType() == DOMNode::ELEMENT_NODE); - } - filterTypeGeneric({ type }, result, (DOMElement*)node, (recurse ? DOCUMENT : NO_RECURSE), true, false); - return result; -} -#else -std::list DOMUtils::filterChildType(const DOMNode::NodeType type, - const DOMNode* node, - bool recurse) { - - std::list filteredChildTypes; - if (!node) - return filteredChildTypes; - - for (auto child = node->getFirstChild(); child; child = child->getNextSibling()) { - if (child->getNodeType() == type) - filteredChildTypes.push_back(child); - if (recurse) { - std::list nested = filterChildType(type, child, recurse); - filteredChildTypes.merge(nested); - - } - } - return filteredChildTypes; -} -#endif - -#if 0 -void DOMUtils::inPostFixOrder(const std::set& elements, - const DOMElement* root, - const bool includeEmbeddedDoc, - std::list& nodes) { - - if (root == NULL) - return; - - for (auto childElem = root->getFirstElementChild(); childElem; childElem = childElem->getNextElementSibling()) { - if (!includeEmbeddedDoc && LOCALNAME(childElem) == "scxml") - continue; - inPostFixOrder(elements, childElem, includeEmbeddedDoc, nodes); - - } - for (auto childElem = root->getFirstElementChild(); childElem; childElem = childElem->getNextElementSibling()) { - if (!includeEmbeddedDoc && TAGNAME(childElem) == XML_PREFIX(root).str() + "scxml") - continue; - - if (elements.find(TAGNAME(childElem)) != elements.end()) { - nodes.push_back((DOMElement*)childElem); - } - } -} - -void DOMUtils::inDocumentOrder(const std::set& elements, - const DOMElement* root, - const bool includeEmbeddedDoc, - std::list& nodes) { - if (root == NULL) - return; - - if (elements.find(TAGNAME(root)) != elements.end()) { - nodes.push_back((DOMElement*)root); - } - - /// @todo: item from getChildNodes is O(N)! - DOMElement* child = root->getFirstElementChild(); - while(child) { - if (includeEmbeddedDoc || TAGNAME(child) != XML_PREFIX(root).str() + "scxml") { - inDocumentOrder(elements, child, includeEmbeddedDoc, nodes); - } - - child = child->getNextElementSibling(); - } -} -#endif } diff --git a/src/uscxml/util/DOM.h b/src/uscxml/util/DOM.h index 7cacd94..49dc4de 100644 --- a/src/uscxml/util/DOM.h +++ b/src/uscxml/util/DOM.h @@ -22,7 +22,7 @@ #include #include -#include +#include #include "uscxml/Common.h" #include @@ -37,8 +37,6 @@ #define LOCALNAME(elem) std::string(X((elem)->getLocalName())) #define LOCALNAME_CAST(elem) LOCALNAME(static_cast(elem)) - - namespace uscxml { class USCXML_API DOMUtils { @@ -53,21 +51,26 @@ public: static bool isMember(const XERCESC_NS::DOMNode* node, const std::list& list); static bool isMember(const XERCESC_NS::DOMNode* node, const XERCESC_NS::DOMNodeList* list); - static std::string xPathForNode(const XERCESC_NS::DOMNode* node, - const std::string& ns = ""); + static std::string xPathForNode(const XERCESC_NS::DOMNode* node, const std::string& ns = ""); static std::string idForNode(const XERCESC_NS::DOMNode* node); static std::list inPostFixOrder(const std::set& elements, const XERCESC_NS::DOMElement* root, - const bool includeEmbeddedDoc = false); + const bool includeEmbeddedDoc = false) { + return filterElementGeneric(elements, root, POSTFIX, includeEmbeddedDoc, true); + } static std::list inDocumentOrder(const std::set& elements, const XERCESC_NS::DOMElement* root, - const bool includeEmbeddedDoc = false); + const bool includeEmbeddedDoc = false) { + return filterElementGeneric(elements, root, DOCUMENT, includeEmbeddedDoc, true); + } static std::list filterChildElements(const std::string& tagName, const XERCESC_NS::DOMElement* node, - bool recurse = false); + bool recurse = false) { + return filterElementGeneric({ tagName }, node, (recurse ? DOCUMENT : NO_RECURSE), true, false); + } static std::list filterChildElements(const std::string& tagName, const std::list& nodeSet, @@ -75,7 +78,10 @@ public: static std::list filterChildType(const XERCESC_NS::DOMNode::NodeType type, const XERCESC_NS::DOMNode* node, - bool recurse = false); + bool recurse = false) { + return filterTypeGeneric({ type }, node, (recurse ? DOCUMENT : NO_RECURSE), true, false); + + } static std::list filterChildType(const XERCESC_NS::DOMNode::NodeType type, const std::list& nodeSet, @@ -94,24 +100,24 @@ public: const bool includeEmbeddedDoc, const bool includeRoot); + static std::list filterElementGeneric(const std::set& elements, + const XERCESC_NS::DOMElement* root, + const Order order, + const bool includeEmbeddedDoc, + const bool includeRoot); + static void filterTypeGeneric(const std::set& types, std::list& result, - const XERCESC_NS::DOMElement* root, + const XERCESC_NS::DOMNode* root, const Order order, const bool includeEmbeddedDoc, const bool includeRoot); -#if 0 - static void inPostFixOrder(const std::set& elements, - const XERCESC_NS::DOMElement* root, - const bool includeEmbeddedDoc, - std::list& nodes); - - static void inDocumentOrder(const std::set& elements, - const XERCESC_NS::DOMElement* root, - const bool includeEmbeddedDoc, - std::list& nodes); -#endif + static std::list filterTypeGeneric(const std::set& types, + const XERCESC_NS::DOMNode* root, + const Order order, + const bool includeEmbeddedDoc, + const bool includeRoot); }; diff --git a/src/uscxml/util/MD5.hpp b/src/uscxml/util/MD5.hpp index b566dc4..c34fee3 100644 --- a/src/uscxml/util/MD5.hpp +++ b/src/uscxml/util/MD5.hpp @@ -26,7 +26,6 @@ extern "C" { #include -#include #include #include #include "uscxml/Common.h" diff --git a/src/uscxml/util/SHA1.hpp b/src/uscxml/util/SHA1.hpp index 97d88d9..584edf5 100644 --- a/src/uscxml/util/SHA1.hpp +++ b/src/uscxml/util/SHA1.hpp @@ -25,7 +25,6 @@ extern "C" { } #include -#include #include #include #include "uscxml/Common.h" diff --git a/test/src/test-extensions.cpp b/test/src/test-extensions.cpp index 5b796c8..7024689 100644 --- a/test/src/test-extensions.cpp +++ b/test/src/test-extensions.cpp @@ -9,6 +9,7 @@ #include #include +#include using namespace uscxml; class MyPausableDelayedEventQueue; diff --git a/test/src/test-gen-c.cpp b/test/src/test-gen-c.cpp index 7af121c..c75492a 100644 --- a/test/src/test-gen-c.cpp +++ b/test/src/test-gen-c.cpp @@ -6,6 +6,8 @@ #include // deque #include // trim +#include + #define USCXML_VERBOSE #include "uscxml/config.h" diff --git a/test/src/test-lifecycle.cpp b/test/src/test-lifecycle.cpp index 59ef1d8..e948e3c 100644 --- a/test/src/test-lifecycle.cpp +++ b/test/src/test-lifecycle.cpp @@ -2,7 +2,7 @@ #include "uscxml/Interpreter.h" #include "uscxml/interpreter/InterpreterMonitor.h" #include "uscxml/interpreter/Logging.h" - +#include #include #include diff --git a/test/src/test-utils.cpp b/test/src/test-utils.cpp index dfeed04..7436015 100644 --- a/test/src/test-utils.cpp +++ b/test/src/test-utils.cpp @@ -12,6 +12,8 @@ #include "uscxml/interpreter/InterpreterImpl.h" #include "uscxml/util/DOM.h" +#include + using namespace uscxml; using namespace XERCESC_NS; diff --git a/test/src/test-validating.cpp b/test/src/test-validating.cpp index 7e0cc31..528812b 100644 --- a/test/src/test-validating.cpp +++ b/test/src/test-validating.cpp @@ -4,6 +4,7 @@ #include "uscxml/debug/InterpreterIssue.h" #include "uscxml/interpreter/Logging.h" #include +#include uscxml::Factory* factory = NULL; -- cgit v0.12