void GlobalDebug::log(::CPLErr code, int num, char const* msg) { std::ostringstream oss; if (code == CE_Failure || code == CE_Fatal) { oss <<"GDAL Failure number=" << num << ": " << msg; throw pdal::gdal_error(oss.str()); } else if (code == CE_Debug) { oss << "Global GDAL debug: " << msg; std::vector<LogPtr>::const_iterator i; std::map<std::ostream*, LogPtr> streams; for (i = m_logs.begin(); i != m_logs.end(); ++i) { streams.insert(std::pair<std::ostream*, LogPtr>((*i)->getLogStream(), *i)); } std::map<std::ostream*, LogPtr>::const_iterator t; for (t = streams.begin(); t != streams.end(); t++) { LogPtr l = t->second; if (l->getLevel() > logDEBUG) l->get(logDEBUG) << oss.str() << std::endl; } return; } else { return; } }
void ClassCheck::checkInterfaceVars( const ClassDefPtr& pClassDef, const InterfaceDefPtr& pInterfaceDef, const StaticContextPtr& pRootCtx, const LogPtr& pLog) const { const list<VariableDeclDefPtr>& classVars = pClassDef->getVariableDecls(); const list<VariableDeclDefPtr>& ifaceVars = pInterfaceDef->getVariableDecls(); map<const wstring, VariableDeclDefPtr> classVarsMap; map<const wstring, VariableDeclDefPtr>::const_iterator mit; list<VariableDeclDefPtr>::const_iterator cit; for (cit = classVars.begin(); cit != classVars.end(); cit++) { const VariableDeclDefPtr& pVariableDecl = *cit; classVarsMap[pVariableDecl->getName()] = pVariableDecl; } list<VariableDeclDefPtr>::const_iterator iit; for (iit = ifaceVars.begin(); iit != ifaceVars.end(); iit++) { const VariableDeclDefPtr& pIfaceVariableDecl = *iit; const wstring& variableName = pIfaceVariableDecl->getName(); if ((mit = classVarsMap.find(variableName)) == classVarsMap.end()) { boost::wformat f(L"Variable %1% defined on interface %2% not found in class."); f % variableName % pInterfaceDef->getClassName(); pLog->log(*pClassDef, msg::ErrAnaClassDef_MissingIfaceVar, f.str()); continue; } const VariableDeclDefPtr& pClassVariableDecl = (*mit).second; if (pIfaceVariableDecl->isStatic() != pClassVariableDecl->isStatic()) { boost::wformat f(L"Variable %1% has invalid scope. See interface %2%"); f % variableName % pInterfaceDef->getClassName(); pLog->log(*pClassVariableDecl, msg::ErrAnaClassDef_IfaceVarWrongScope, f.str()); continue; } if (!SemanticAnalysis::isTypeAssignableFrom( pClassVariableDecl->getDeclaredType(), pIfaceVariableDecl->getDeclaredType(), pRootCtx)) { boost::wformat f(L"Can't convert from %1% to %2% at class variable %3% defined on interface %4%"); f % pIfaceVariableDecl->getDeclaredType()->toString()% pClassVariableDecl->getDeclaredType()->toString() % variableName % pInterfaceDef->getClassName(); pLog->log(*pClassVariableDecl, msg::ErrAnaClassDef_IfaceVarIncompTypes, f.str()); continue; } } }
void ClassCheck::doCheck( const StaticContextPtr& pRootCtx, const ASTNodePtr& pNode, const LogPtr& pLog) const { if (pNode->getASTNodeType() != ASTN_CLASS) { return; } ClassDefPtr pClassDef = boost::static_pointer_cast<ClassDef>(pNode); const list<const wstring>& ifaces = pClassDef->getImplementedInterfaces(); list<const wstring>::const_iterator it; for (it = ifaces.begin(); it != ifaces.end(); it++) { const wstring& ifaceName = *it; CStaticContextEntryPtr pEntry; InterfaceDefPtr pInterfaceDef; if (!pRootCtx->lookup(ifaceName, pEntry)) { boost::wformat f(L"Interface %1% not found."); f % ifaceName; pLog->log(*pClassDef, msg::ErrAnaClassDef_IfaceNotFound, f.str()); continue; } else if (!pEntry->getInterface(pInterfaceDef)) { boost::wformat f(L"%1% is not an interface."); f % ifaceName; pLog->log(*pClassDef, msg::ErrAnaClassDef_NotAnIface, f.str()); continue; } checkInterfaceParams(pClassDef, pInterfaceDef, pRootCtx, pLog); checkInterfaceVars(pClassDef, pInterfaceDef, pRootCtx, pLog); } const list<VariableDeclDefPtr>& vars = pClassDef->getVariableDecls(); list<VariableDeclDefPtr>::const_iterator vit; for (vit = vars.begin(); vit != vars.end(); vit++) { const VariableDeclDefPtr& pVar = *vit; if (pVar->getValue().get() == NULL) { boost::wformat f(L"Unassigned class variable %1%."); f % pVar->getName(); pLog->log(*pClassDef, msg::ErrAnaClassDef_UnassignedClassVar, f.str()); continue; } } }
void PipelineExecutor::setLogStream(std::ostream& strm) { LogPtr log = pdal::LogPtr(new pdal::Log("pypipeline", &strm)); log->setLevel(m_logLevel); m_manager.setLog(log); }
TEST(SQLiteTest, testVersionInfo) { LogPtr log = std::shared_ptr<pdal::Log>(new pdal::Log("spver", "stdout")); log->setLevel(LogLevel::Debug); const std::string filename(Support::temppath("spver.sqlite")); FileUtils::deleteFile(filename); SQLite db(filename, LogPtr(log)); db.connect(true); db.loadSpatialite(); const std::string p = db.getSQLiteVersion(); EXPECT_EQ(p[0], '3'); // 3.8.9 as of this commit const std::string q = db.getSpatialiteVersion(); EXPECT_EQ(q[0], '4'); // 4.2.0 as of this commit // FileUtils::deleteFile(filename); }
void ClassCheck::checkInterfaceParams( const ClassDefPtr& pClassDef, const InterfaceDefPtr& pInterfaceDef, const StaticContextPtr& pRootCtx, const LogPtr& pLog) const { const map<const wstring, FormalParamDefPtr>& ifaceFormalParams = pInterfaceDef->getFormalParametersMap(); const map<const wstring, FormalParamDefPtr>& classFormalParams = pClassDef->getFormalParametersMap(); if (ifaceFormalParams.empty()) { return; } map<const wstring, FormalParamDefPtr>::const_iterator iit; map<const wstring, FormalParamDefPtr>::const_iterator cit; for (iit = ifaceFormalParams.begin(); iit != ifaceFormalParams.end(); iit++) { const FormalParamDefPtr& pIfaceParam = (*iit).second; cit = classFormalParams.find(pIfaceParam->getParamName()); if (cit == classFormalParams.end()) { boost::wformat f(L"Interface parameter %1% not found."); f % pIfaceParam->getParamName(); pLog->log(*pClassDef, msg::ErrAnaClassDef_MissingIfaceParam, f.str()); continue; } const FormalParamDefPtr& pClassParam = (*cit).second; if (!SemanticAnalysis::isTypeAssignableFrom( pClassParam->getType(), pIfaceParam->getType(), pRootCtx)) { boost::wformat f( L"Can't convert from %1% to %2% at class parameter %3% defined on interface %4%."); f % pIfaceParam->getType()->toString() % pClassParam->getType()->toString() % pIfaceParam->getParamName() % pInterfaceDef->getClassName(); pLog->log(*pClassDef, msg::ErrAnaClassDef_IfaceParamIncompTypes, f.str()); continue; } } for (cit = classFormalParams.begin(); cit != classFormalParams.end(); cit++) { const wstring& classParamName = (*cit).first; iit = ifaceFormalParams.find(classParamName); if (iit == ifaceFormalParams.end()) { boost::wformat f(L"Class parameter %1% not defined on interface %2%."); f % classParamName % pInterfaceDef->getClassName(); pLog->log(*pClassDef, msg::ErrAnaClassDef_ClassParamNotFoundIface, f.str()); continue; } } }
int App::execute(StringList& cmdArgs, LogPtr& log) { ProgramArgs args; addArgs(args); try { args.parseSimple(cmdArgs); } catch (arg_val_error const& e) { Utils::printError(e.what()); return -1; } log.reset(new Log("PDAL", m_log, m_logtiming)); if (m_logLevel != LogLevel::None) log->setLevel(m_logLevel); else if (m_debug) log->setLevel(LogLevel::Debug); log->get(LogLevel::Debug) << "Debugging..." << std::endl; PluginManager<Stage>::setLog(log); PluginManager<Kernel>::setLog(log); #ifndef _WIN32 if (m_debug) { signal(SIGSEGV, [](int sig) { logPtr->get(LogLevel::Debug) << "Segmentation fault (signal 11)\n"; StringList lines = Utils::backtrace(); for (const auto& l : lines) logPtr->get(LogLevel::Debug) << l << std::endl; exit(1); }); } #endif m_command = Utils::tolower(m_command); if (!m_command.empty()) { int ret = 0; std::string name("kernels." + m_command); Kernel *kernel = PluginManager<Kernel>::createObject(name); if (kernel) { if (m_help) cmdArgs.push_back("--help"); // This shouldn't throw. If it does, it's something awful, so // not cleaning up seems inconsequential. log->setLeader("pdal " + m_command); ret = kernel->run(cmdArgs, log); delete kernel; // IMPORTANT - The kernel must be destroyed before GDAL // drivers are unregistered or GDAL will attempt to destroy // resources more than once, resulting in a crash. gdal::unregisterDrivers(); } else log->get(LogLevel::Error) << "Command '" << m_command << "' not recognized" << std::endl << std::endl; return ret; } if (m_showVersion) outputVersion(); else if (m_showDrivers) outputDrivers(); else if (m_showOptions.size()) { if (m_showOptions == "all") outputOptions(); else outputOptions(m_showOptions, m_out); } else outputHelp(args); return 0; }
void TypeInference::inferTypes( ValueDef& valueDef, StaticContextPtr& pMemberCtx, const LogPtr& pLog) { switch (valueDef.getValueType()) { case OBJECT_INIT: { const ObjectInitValueDef& objectInitDef = static_cast<const ObjectInitValueDef&>(valueDef); TypePtr pType = TypePtr( new ReferenceType(OBJECT_REF_TYPE, objectInitDef.getClassName())); valueDef.setInferredType(pType); const map<const wstring, ActualParamDefPtr>& actualParamsMap = objectInitDef.getActualParamsMap(); map<const wstring, ActualParamDefPtr>::const_iterator it; for (it = actualParamsMap.begin(); it != actualParamsMap.end(); it++) { const ActualParamDefPtr& pActualParamDef = (*it).second; const ValueDefPtr& pParamValueDef = pActualParamDef->getValue(); inferTypes(*pParamValueDef, pMemberCtx, pLog); } } break; case ARRAY_INIT: { const ArrayInitValueDef& arrayInitDef = static_cast<const ArrayInitValueDef&>(valueDef); valueDef.setInferredType(arrayInitDef.getDeclaredType()); const list<ValueDefPtr>& arrayValues = arrayInitDef.getValues(); list<ValueDefPtr>::const_iterator it; for (it = arrayValues.begin(); it != arrayValues.end(); it++) { const ValueDefPtr& pArrayValue = *it; inferTypes(*pArrayValue, pMemberCtx, pLog); } } break; case LITERAL: { const LiteralValueDef& literalDef = static_cast<const LiteralValueDef&>(valueDef); switch (literalDef.getLiteralType()) { case INTEGER_LITERAL: valueDef.setInferredType(P_INTEGER_TYPE); break; case FLOAT_LITERAL: valueDef.setInferredType(P_FLOAT_TYPE); break; case STRING_LITERAL: valueDef.setInferredType(P_STRING_TYPE); break; default: assert(false); break; } } break; case REFERENCE_PATH: { const ReferencePathValueDef& referencePathDef = static_cast<const ReferencePathValueDef&>(valueDef); const list<const wstring>& path = referencePathDef.getReferencePath(); StaticContextEntryPtr pEntry; TypePtr pCurrentType; list<const wstring>::const_iterator it; wstring parentPath(L""); for (it = path.begin(); it != path.end(); it++) { const wstring& pathElement = *it; if (it == path.begin()) { CStaticContextEntryPtr pEntry; if (!pMemberCtx->lookup(pathElement, pEntry)) { boost::wformat f(L"Unable to resolve name %1%"); f % pathElement; pLog->log(referencePathDef, msg::ErrAnaTypeInfer_NameNotInContext, f.str()); return; } else { switch (pEntry->getStaticEntryType()) { case CLASS_DEF_CTX_ENTRY: { TypePtr pType(new ReferenceType(CLASS_REF_TYPE, pEntry->getName())); pCurrentType = pType; } break; case INTERFACE_DEF_CTX_ENTRY: { TypePtr pType(new ReferenceType(CLASS_REF_TYPE, pEntry->getName())); pCurrentType = pType; } break; case VARIABLE_DEF_CTX_ENTRY: { VariableDeclDefPtr pVariableDef; pEntry->getVariable(pVariableDef); if (pMemberCtx->isStatic() && !pVariableDef->isStatic()) { boost::wformat f(L"Cannot refer to a non static variable from an static context: %1%"); f % pathElement; pLog->log(referencePathDef, msg::ErrAnaTypeInfer_NonStaticVarRef, f.str()); return; } else { pCurrentType = pVariableDef->getDeclaredType(); } } break; case FORMAL_PARAM_DEF_CTX_ENTRY: { if (pMemberCtx->isStatic()) { boost::wformat f(L"Cannot refer to a class parameter from an static context: %1%"); f % pathElement; pLog->log(referencePathDef, msg::ErrAnaTypeInfer_NonStaticParamRef, f.str()); return; } FormalParamDefPtr pFormalParamDef; pEntry->getFormalParam(pFormalParamDef); pCurrentType = pFormalParamDef->getType(); } break; default: assert(false); return; } } } else { assert(pCurrentType.get() != NULL); StaticContextPtr pRootCtx; pMemberCtx->getRootContext(pRootCtx); if (!followPathElement( *pCurrentType, *pRootCtx, pathElement, pCurrentType)) { boost::wformat f(L"%1% is not a member of %2%"); f % pathElement % parentPath; pLog->log(referencePathDef, msg::ErrAnaTypeInfer_NotAMember, f.str()); return; } } if (parentPath.size()) { parentPath.append(L"."); } parentPath.append(pathElement); } assert(pCurrentType.get() != NULL); valueDef.setInferredType(pCurrentType); } break; default: assert(false); break; } }