diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..0bad24b6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +servant/makefile/tars-tools.cmake +.idea +/cmake-build-debug-177 diff --git a/CMakeLists.txt b/CMakeLists.txt index 03531a40..b51f1715 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ ENDIF() add_subdirectory(util) add_subdirectory(tools) add_subdirectory(servant) +add_subdirectory(mock) IF (NOT ${ONLY_LIB}) add_subdirectory(examples) diff --git a/Changelist-3.x.md b/Changelist-3.x.md index 4343f4b4..2c9184ca 100644 --- a/Changelist-3.x.md +++ b/Changelist-3.x.md @@ -1,3 +1,41 @@ +# v3.0.19 20240202 + +## en +- fix: tars-tools.cmake in windows +- fix: tc_port fix forkExec bug +- fix: remote logger remove ServerConfig::Context +- fix: current not report one_way stat(useless) +- fix: StatReport interface, remove parameters not used +- fix: tc_option support parameter with ", like this: --test="abc" +- fix: When the server actively closes the connection, RPC may cause memory leak issues +- fix: push callback may crash +- fix: KeepAliveNodeFHelper no singleton +- fix: gzip compress coredump +- fix: PingCallback set servantPrx +- fix: remote config, when tarsconfig timeout not use local config file bug +- fix: tars-tools.cmake.in add: list(APPEND TARS_TOOL_FLAG "") +- fix: trace, no not depend ServerConfig +- fix: tars-tools.cmake set TARS_SSL/TARS_MYSQL/TARS_HTTP2 depends tarscpp compiler +- feat: modify xxx_fcontext name to avoid conflict with other co lib +- feat: rpc add time distr report +- feat: tc_port add getDiskInfo/getCpuLoad/getUPTime/getPidStartTime/getPidMemUsed/getCwd/kill and support mac/windows/linux +- feat: tc_port add closeAllFileDescriptors in linux/mac +- feat: tc_file add joinPaths/toAbsolute +- feat: Application first bind adminObj, then initialize, then bind other objs +- feat: EndpointInfo add toEndpointF +- feat: AdminF.tars add getPid +- feat: ServantHandle in servant use shared ptr +- feat: ClientConfig change to Communicator subclass, no global static object +- feat: ClientConfig add context, when call other core tars server with this context, node_name in context +- feat: add ApplicationCommunicator to support multi Appliations in one process +- feat: support master-slave mode in frameworkPro +- feat: Application add ServerBaseInfo in Application +- optimize: bind after initialize when Applicaion start +- optimize: RemoteConfig remove singleton +- optimize: loading local ip list cache +- optimize: AppCache only initialize once +- optimize: global rolllog only init once + # v3.0.18 20231106 ### en - fix: udp ipv6 bug diff --git a/cmake/Common.cmake b/cmake/Common.cmake index e8e3817d..d6c3c9ae 100755 --- a/cmake/Common.cmake +++ b/cmake/Common.cmake @@ -1,6 +1,6 @@ -set(TARS_VERSION "3.0.18") +set(TARS_VERSION "3.0.19") add_definitions(-DTARS_VERSION="${TARS_VERSION}") set(CMAKE_VERBOSE_MAKEFILE off) @@ -11,6 +11,13 @@ IF (CMAKE_BUILD_TYPE STREQUAL "") ENDIF() +# 设置一个选项,用于控制是否定义 TARS_STD_SHARED_PTR 宏 +option(TARS_STD_SHARED_PTR "Use std::shared_ptr instead of tars::AutoPtr" OFF) +if(TARS_STD_SHARED_PTR) + add_definitions(-DTARS_STD_SHARED_PTR) +endif() + + #编译的可执行程序输出目录 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) @@ -83,8 +90,7 @@ IF (UNIX) ELSEIF (WIN32) set(PLATFORM "window") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /wd4101 /wd4244 /wd4996 /wd4091 /wd4503 /wd4819 /wd4200 /wd4800 /wd4267 /wd4251 /wd4275") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj" ) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /wd4101 /wd4244 /wd4996 /wd4091 /wd4503 /wd4819 /wd4200 /wd4800 /wd4267 /wd4251 /wd4275 /bigobj") SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") @@ -95,6 +101,10 @@ ELSEIF (WIN32) SET(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /DEBUG") SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /OPT:ICF /OPT:REF /DEBUG") + add_compile_options("$<$:/utf-8>") + add_compile_options("$<$:/utf-8>") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /ZI") + ELSE () MESSAGE(STATUS "================ ERROR: This platform is unsupported!!! ================") ENDIF (UNIX) @@ -119,5 +129,6 @@ message("BIN: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}") message("TARS2CPP: ${TARS2CPP}") #message("TARS_OPENTRACKING: ${TARS_OPENTRACKING}") message("ONLY_LIB: ${ONLY_LIB}" ) +message("TARS_STD_SHARED_PTR: ${TARS_STD_SHARED_PTR}" ) #------------------------------------------------------------- diff --git a/cmake/Thirdparty.cmake b/cmake/Thirdparty.cmake index 10c373e5..a48edfc1 100755 --- a/cmake/Thirdparty.cmake +++ b/cmake/Thirdparty.cmake @@ -272,7 +272,7 @@ if (TARS_MYSQL) DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download PREFIX ${CMAKE_BINARY_DIR} INSTALL_DIR ${CMAKE_SOURCE_DIR} - CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/mysql -DBUILD_CONFIG=mysql_release + CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/mysql -DBUILD_CONFIG=mysql_release -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci SOURCE_DIR ${CMAKE_BINARY_DIR}/src/mysql-lib BUILD_IN_SOURCE 1 BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release @@ -288,7 +288,7 @@ if (TARS_MYSQL) DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download PREFIX ${CMAKE_BINARY_DIR} INSTALL_DIR ${CMAKE_SOURCE_DIR} - CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DDISABLE_SHARED=1 -DSTACK_DIRECTION=1 -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} + CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/mysql -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8mb4_general_ci -DDISABLE_SHARED=1 -DSTACK_DIRECTION=1 -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} SOURCE_DIR ${CMAKE_BINARY_DIR}/src/mysql-lib BUILD_IN_SOURCE 1 BUILD_COMMAND make mysqlclient diff --git a/examples/AuthDemo/Client/main.cpp b/examples/AuthDemo/Client/main.cpp index 7dd8af15..7aa02564 100644 --- a/examples/AuthDemo/Client/main.cpp +++ b/examples/AuthDemo/Client/main.cpp @@ -106,7 +106,7 @@ void asyncCall(int c) //发起远程调用 for (int i = 0; i < c; ++i) { - HelloPrxCallbackPtr p = new HelloCallback(t, i, c); + HelloPrxCallbackPtr p(new HelloCallback(t, i, c)); try { diff --git a/examples/CoroutineDemo/BServer/BServantImp.cpp b/examples/CoroutineDemo/BServer/BServantImp.cpp index 0c13df20..830026e7 100644 --- a/examples/CoroutineDemo/BServer/BServantImp.cpp +++ b/examples/CoroutineDemo/BServer/BServantImp.cpp @@ -66,7 +66,7 @@ class AServantCoroCallback : public AServantCoroPrxCallback int _iOut; string _sOut; }; -typedef tars::TC_AutoPtr AServantCoroCallbackPtr; +// typedef tars::TC_AutoPtr AServantCoroCallbackPtr; int BServantImp::test(tars::TarsCurrentPtr current) { return 0;} @@ -111,21 +111,21 @@ tars::Int32 BServantImp::testCoroParallel(const std::string& sIn, std::string &s int iIn = 5; - CoroParallelBasePtr sharedPtr = new CoroParallelBase(2); + CoroParallelBasePtr sharedPtr(new CoroParallelBase(2)); - AServantCoroCallbackPtr cb1 = new AServantCoroCallback(); + AServantCoroPrxCallbackPtr cb1(new AServantCoroCallback()); cb1->setCoroParallelBasePtr(sharedPtr); _pPrx->coro_testInt(cb1, iIn); - AServantCoroCallbackPtr cb2 = new AServantCoroCallback(); + AServantCoroPrxCallbackPtr cb2(new AServantCoroCallback()); cb2->setCoroParallelBasePtr(sharedPtr); _pPrx->coro_testStr(cb2, sIn); coroWhenAll(sharedPtr); - if(cb1->_iRet == 0 && cb2->_iRet == 0) + if(((AServantCoroCallback*)(cb1.get()))->_iRet == 0 && ((AServantCoroCallback*)(cb2.get()))->_iRet == 0) { - sOut = cb2->_sOut; + sOut = ((AServantCoroCallback*)(cb2.get()))->_sOut; iRet = 0; } diff --git a/examples/CoroutineDemo/testParallelCoro/main.cpp b/examples/CoroutineDemo/testParallelCoro/main.cpp index 10faca07..5937cf23 100644 --- a/examples/CoroutineDemo/testParallelCoro/main.cpp +++ b/examples/CoroutineDemo/testParallelCoro/main.cpp @@ -55,7 +55,7 @@ class BServantCoroCallback : public BServantCoroPrxCallback int _iOut; string _sOut; }; -typedef tars::TC_AutoPtr BServantCoroCallbackPtr; +// typedef tars::TC_AutoPtr BServantCoroCallbackPtr; //////////////////////////////////////////// //继承框架的协程类 @@ -93,11 +93,11 @@ void TestCoroutine::handle() { CoroParallelBasePtr sharedPtr = new CoroParallelBase(2); - BServantCoroCallbackPtr cb1 = new BServantCoroCallback(); + BServantCoroPrxCallbackPtr cb1(new BServantCoroCallback()); cb1->setCoroParallelBasePtr(sharedPtr); _prx->coro_testCoroSerial(cb1, sIn); - BServantCoroCallbackPtr cb2 = new BServantCoroCallback(); + BServantCoroPrxCallbackPtr cb2(new BServantCoroCallback()); cb2->setCoroParallelBasePtr(sharedPtr); _prx->coro_testCoroParallel(cb2, sIn); @@ -105,7 +105,7 @@ void TestCoroutine::handle() // cout << "ret1:" << cb1->_sOut << "|ret2:" << cb2->_sOut << endl; - if(cb1->_iRet == 0 && cb2->_iRet == 0 && cb1->_iException == 0 && cb2->_iException == 0) + if(((BServantCoroCallback*)(cb1.get()))->_iRet == 0 && ((BServantCoroCallback*)(cb2.get()))->_iRet == 0 && ((BServantCoroCallback*)(cb1.get()))->_iException == 0 && ((BServantCoroCallback*)(cb2.get()))->_iException == 0) { ++sum; } diff --git a/examples/CustomDemo/CustomClient/main.cpp b/examples/CustomDemo/CustomClient/main.cpp index 5e5eb3fb..f5f4afdb 100644 --- a/examples/CustomDemo/CustomClient/main.cpp +++ b/examples/CustomDemo/CustomClient/main.cpp @@ -158,7 +158,7 @@ void asyncCall(int c) { try { - CustomCallBackPtr cb = new CustomCallBack(); + ServantProxyCallbackPtr cb(new CustomCallBack()); param.servantPrx->rpc_call_async(param.servantPrx->tars_gen_requestid(), "doCustomFunc", buffer.c_str(), buffer.length(), cb); } catch(exception& e) diff --git a/examples/PushCallbackDemo/Client/main.cpp b/examples/PushCallbackDemo/Client/main.cpp index 8b8d5f7b..8b19e3d4 100644 --- a/examples/PushCallbackDemo/Client/main.cpp +++ b/examples/PushCallbackDemo/Client/main.cpp @@ -61,7 +61,10 @@ int main(int argc, char *argv[]) _comm->setProperty(conf); HelloPrx pPrx = _comm->stringToProxy(helloObj); - pPrx->tars_set_push_callback(new PushCallbackImp()); + + ServantProxyCallbackPtr cbPush(new PushCallbackImp()); + + pPrx->tars_set_push_callback(cbPush); pPrx->registerPush(); while(g_count < 10) diff --git a/examples/PushDemo/PushClient/TestRecvThread.cpp b/examples/PushDemo/PushClient/TestRecvThread.cpp index 3a820d03..a3e30f02 100755 --- a/examples/PushDemo/PushClient/TestRecvThread.cpp +++ b/examples/PushDemo/PushClient/TestRecvThread.cpp @@ -127,7 +127,7 @@ RecvThread::RecvThread(int second):_second(second), _bTerminate(false) void RecvThread::run(void) { - TestPushCallBackPtr cbPush = new TestPushCallBack(); + ServantProxyCallbackPtr cbPush(new TestPushCallBack()); _prx->tars_set_push_callback(cbPush); string buf("heartbeat"); @@ -139,7 +139,7 @@ void RecvThread::run(void) { try { - TestPushCallBackPtr cb = new TestPushCallBack(); + ServantProxyCallbackPtr cb(new TestPushCallBack()); _prx->rpc_call_async(_prx->tars_gen_requestid(), "printResult", buf.c_str(), buf.length(), cb); } catch(TarsException& e) diff --git a/examples/QuickStartDemo/HelloServer/Client/main.cpp b/examples/QuickStartDemo/HelloServer/Client/main.cpp index 30741587..ff868261 100644 --- a/examples/QuickStartDemo/HelloServer/Client/main.cpp +++ b/examples/QuickStartDemo/HelloServer/Client/main.cpp @@ -114,7 +114,7 @@ void asyncCall(int c) //发起远程调用 for (int i = 0; i < c; ++i) { - HelloPrxCallbackPtr p = new HelloCallback(t, i, c); + HelloPrxCallbackPtr p(new HelloCallback(t, i, c)); try { @@ -172,9 +172,10 @@ void syncTupCall(int c) rsp.decode(package.sBuffer.data(), package.sBuffer.size()); - int ret = rsp.get(""); + int ret = rsp.get(""); string sRsp = rsp.get("sRsp"); + cout << "ret:" << ret << ", rsp:" << sRsp << endl; // assert(ret == 0); // assert(sRsp == buffer); } @@ -262,7 +263,7 @@ void asyncTupCall(int c) vector buff; req.encode(buff); - ServantProxyCallbackPtr p = new TupCallback(t, i, c); + ServantProxyCallbackPtr p(new TupCallback(t, i, c)); param.pPrx->rpc_call_async(req.getRequestId(), "testHello", buff.data(), buff.size(), p); } diff --git a/examples/QuickStartDemo/ProxyServer/Server/ProxyImp.cpp b/examples/QuickStartDemo/ProxyServer/Server/ProxyImp.cpp index 1cfc1905..ca18509e 100644 --- a/examples/QuickStartDemo/ProxyServer/Server/ProxyImp.cpp +++ b/examples/QuickStartDemo/ProxyServer/Server/ProxyImp.cpp @@ -68,7 +68,7 @@ tars::Int32 ProxyImp::testProxy(const std::string& sIn, std::string &sOut, tars: { current->setResponse(false); - TestApp::HelloPrxCallbackPtr cb = new HelloCallback(current); + TestApp::HelloPrxCallbackPtr cb(new HelloCallback(current)); _prx->tars_set_timeout(3000)->async_testHello(cb,sIn); } diff --git a/examples/UdpDemo/Client/main.cpp b/examples/UdpDemo/Client/main.cpp index 4d466b19..41da543b 100644 --- a/examples/UdpDemo/Client/main.cpp +++ b/examples/UdpDemo/Client/main.cpp @@ -111,7 +111,7 @@ void asyncCall(int c) if(request_count - callback_count < 100) { i++; request_count++; - HelloPrxCallbackPtr p = new HelloCallback(t, i, c); + HelloPrxCallbackPtr p(new HelloCallback(t, i, c)); try { param.pPrx->async_testHello(p, buffer); } diff --git a/examples/UtilDemo/demo-server/demo_server.cpp b/examples/UtilDemo/demo-server/demo_server.cpp index c6bf5797..6174df54 100644 --- a/examples/UtilDemo/demo-server/demo_server.cpp +++ b/examples/UtilDemo/demo-server/demo_server.cpp @@ -204,7 +204,7 @@ class MyServer : public TC_EpollServer void initialize() { - g_group.start(1); + g_group.start(); g_logger.init("./debug", 1024 * 1024, 10); g_logger.modFlag(TC_RollLogger::HAS_LEVEL | TC_RollLogger::HAS_PID, true); diff --git a/mock/CMakeLists.txt b/mock/CMakeLists.txt new file mode 100755 index 00000000..a29ebdbf --- /dev/null +++ b/mock/CMakeLists.txt @@ -0,0 +1,10 @@ + +include_directories(../) +file(GLOB_RECURSE SRC_FILES *.cpp) +add_library(tarsmock ${SRC_FILES}) + +add_dependencies(tarsmock tarsservant) +install(DIRECTORY . DESTINATION include/mock FILES_MATCHING PATTERN "*.h") + +install(TARGETS tarsmock RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + diff --git a/mock/ConfigImp.cpp b/mock/ConfigImp.cpp new file mode 100755 index 00000000..00c2f7c0 --- /dev/null +++ b/mock/ConfigImp.cpp @@ -0,0 +1,11 @@ + +#include "ConfigImp.h" + +map ConfigImp::files; +std::mutex ConfigImp::_mutex; + +void ConfigImp::setConfigFile(const string &name, const string &content) +{ + std::lock_guard lock(_mutex); + files[name] = content; +} diff --git a/unit-test/server/framework/ConfigImp.h b/mock/ConfigImp.h similarity index 93% rename from unit-test/server/framework/ConfigImp.h rename to mock/ConfigImp.h index 21d675f3..fb01ee62 100755 --- a/unit-test/server/framework/ConfigImp.h +++ b/mock/ConfigImp.h @@ -27,7 +27,7 @@ class ConfigImp : public Config */ virtual void initialize() { - files["test.conf"] = "test-content"; + }; /** @@ -53,6 +53,8 @@ class ConfigImp : public Config { LOG_CONSOLE_DEBUG << app << ", " << server << ", " << filename << endl; + std::lock_guard lock(_mutex); + map::iterator it =files.find(filename); if(it!=files.end()){ config = it->second; @@ -144,8 +146,17 @@ class ConfigImp : public Config return 0; } + + /** + * + * @param name + * @param content + */ + static void setConfigFile(const string &name, const string &content); + private: - map files; + static std::mutex _mutex; + static map files; }; #endif /* TARS_TARS_TEST_TESTCODE_INCLUDE_STUB_CONFIGIMP_H_ */ diff --git a/unit-test/server/framework/DbHandle.cpp b/mock/DbHandle.cpp similarity index 78% rename from unit-test/server/framework/DbHandle.cpp rename to mock/DbHandle.cpp index 70b1c605..b2efef07 100755 --- a/unit-test/server/framework/DbHandle.cpp +++ b/mock/DbHandle.cpp @@ -1,16 +1,21 @@ - + #include #include -#include "DbHandle.h" +#include "mock/DbHandle.h" + + +////////////////////////////////////////////////////// -TC_ReadersWriterData CDbHandle::_objectsCache; -TC_ReadersWriterData CDbHandle::_setDivisionCache; -TC_ReadersWriterData > CDbHandle::_mapGroupPriority; +static ObjectsCache _objectsCache; + +CDbHandle::SetDivisionCache CDbHandle::_setDivisionCache; +std::map CDbHandle::_mapGroupPriority; +std::mutex CDbHandle::_mutex; //key-ip, value-组编号 -TC_ReadersWriterData > CDbHandle::_groupIdMap; +map CDbHandle::_groupIdMap; //key-group_name, value-组编号 -TC_ReadersWriterData > CDbHandle::_groupNameMap; +//map CDbHandle::_groupNameMap; int CDbHandle::init(TC_Config *pconf) { @@ -19,8 +24,10 @@ int CDbHandle::init(TC_Config *pconf) vector CDbHandle::findObjectById(const string& id) { + std::lock_guard lock(_mutex); + ObjectsCache::iterator it; - ObjectsCache& usingCache = _objectsCache.getReaderData(); + ObjectsCache& usingCache = _objectsCache; if ((it = usingCache.find(id)) != usingCache.end()) { @@ -37,10 +44,11 @@ vector CDbHandle::findObjectById(const string& id) int CDbHandle::findObjectById4All(const string& id, vector& activeEp, vector& inactiveEp) { + std::lock_guard lock(_mutex); TLOGDEBUG(__FUNCTION__ << " id: " << id << endl); ObjectsCache::iterator it; - ObjectsCache& usingCache = _objectsCache.getReaderData(); + ObjectsCache& usingCache = _objectsCache; if ((it = usingCache.find(id)) != usingCache.end()) { @@ -112,8 +120,9 @@ int CDbHandle::findObjectByIdInSameGroup(const string& id, const string& ip, vec return findObjectById4All(id, activeEp, inactiveEp); } + std::lock_guard lock(_mutex); ObjectsCache::iterator it; - ObjectsCache& usingCache = _objectsCache.getReaderData(); + ObjectsCache& usingCache = _objectsCache; if ((it = usingCache.find(id)) != usingCache.end()) { @@ -147,7 +156,8 @@ int CDbHandle::findObjectByIdInGroupPriority(const std::string& sID, const std:: return findObjectById4All(sID, vecActive, vecInactive); } - ObjectsCache& usingCache = _objectsCache.getReaderData(); + std::lock_guard lock(_mutex); + ObjectsCache& usingCache = _objectsCache; ObjectsCache::iterator itObject = usingCache.find(sID); if (itObject == usingCache.end()) return 0; @@ -159,7 +169,7 @@ int CDbHandle::findObjectByIdInGroupPriority(const std::string& sID, const std:: } //启用分组,但同组中没有找到,在优先级序列中查找 - std::map & mapPriority = _mapGroupPriority.getReaderData(); + std::map & mapPriority = _mapGroupPriority; for (std::map::iterator it = mapPriority.begin(); it != mapPriority.end() && vecActive.empty(); it++) { if (it->second.setGroupID.count(iClientGroupID) == 0) @@ -196,8 +206,9 @@ int CDbHandle::findObjectByIdInSameStation(const std::string& sID, const std::st vecActive.clear(); vecInactive.clear(); + std::lock_guard lock(_mutex); //获得station所有组 - std::map & mapPriority = _mapGroupPriority.getReaderData(); + std::map & mapPriority = _mapGroupPriority; std::map::iterator itGroup = mapPriority.end(); for (itGroup = mapPriority.begin(); itGroup != mapPriority.end(); itGroup++) { @@ -212,7 +223,7 @@ int CDbHandle::findObjectByIdInSameStation(const std::string& sID, const std::st return -1; } - ObjectsCache& usingCache = _objectsCache.getReaderData(); + ObjectsCache& usingCache = _objectsCache; ObjectsCache::iterator itObject = usingCache.find(sID); if (itObject == usingCache.end()) return 0; @@ -229,7 +240,8 @@ int CDbHandle::findObjectByIdInSameSet(const string& sID, const vector& string sSetArea = vtSetInfo[0] + "." + vtSetInfo[1]; string sSetId = vtSetInfo[0] + "." + vtSetInfo[1] + "." + vtSetInfo[2]; - SetDivisionCache& usingSetDivisionCache = _setDivisionCache.getReaderData(); + std::lock_guard lock(_mutex); + SetDivisionCache& usingSetDivisionCache = _setDivisionCache; SetDivisionCache::iterator it = usingSetDivisionCache.find(sID); if (it == usingSetDivisionCache.end()) { @@ -306,17 +318,16 @@ int CDbHandle::findObjectByIdInSameSet(const string& sSetId, const vector lock(_mutex); //全量更新 if (updateAll) { - _objectsCache.getWriterData() = objCache; - _objectsCache.swap(); + _objectsCache = objCache; } else { //用查询数据覆盖一下 - _objectsCache.getWriterData() = _objectsCache.getReaderData(); - ObjectsCache& tmpObjCache = _objectsCache.getWriterData(); + ObjectsCache& tmpObjCache = _objectsCache; ObjectsCache::const_iterator it = objCache.begin(); for (; it != objCache.end(); it++) @@ -324,23 +335,21 @@ void CDbHandle::updateObjectsCache(const ObjectsCache& objCache, bool updateAll) //增量的时候加载的是服务的所有节点,因此这里直接替换 tmpObjCache[it->first] = it->second; } - _objectsCache.swap(); } } void CDbHandle::updateInactiveObjectsCache(const ObjectsCache& objCache, bool updateAll) { + std::lock_guard lock(_mutex); //全量更新 if (updateAll) { - _objectsCache.getWriterData() = objCache; - _objectsCache.swap(); + _objectsCache = objCache; } else { //用查询数据覆盖一下 - _objectsCache.getWriterData() = _objectsCache.getReaderData(); - ObjectsCache& tmpObjCache = _objectsCache.getWriterData(); + ObjectsCache& tmpObjCache = _objectsCache; ObjectsCache::const_iterator it = objCache.begin(); for (; it != objCache.end(); it++) @@ -348,24 +357,22 @@ void CDbHandle::updateInactiveObjectsCache(const ObjectsCache& objCache, bool up //增量的时候加载的是服务的所有节点,因此这里直接替换 tmpObjCache[it->first].vInactiveEndpoints.push_back((it->second).vInactiveEndpoints[0]); } - _objectsCache.swap(); } } void CDbHandle::updateActiveObjectsCache(const ObjectsCache& objCache, bool updateAll) { + std::lock_guard lock(_mutex); //全量更新 if (updateAll) { - _objectsCache.getWriterData() = objCache; - _objectsCache.swap(); + _objectsCache = objCache; } else { //用查询数据覆盖一下 - _objectsCache.getWriterData() = _objectsCache.getReaderData(); - ObjectsCache& tmpObjCache = _objectsCache.getWriterData(); + ObjectsCache& tmpObjCache = _objectsCache; ObjectsCache::const_iterator it = objCache.begin(); for (; it != objCache.end(); it++) @@ -373,31 +380,50 @@ void CDbHandle::updateActiveObjectsCache(const ObjectsCache& objCache, bool upda //增量的时候加载的是服务的所有节点,因此这里直接替换 tmpObjCache[it->first].vActiveEndpoints.push_back((it->second).vActiveEndpoints[0]); } - _objectsCache.swap(); } } +void CDbHandle::printActiveEndPoint(const string& objName) +{ + std::lock_guard lock(_mutex); + { + LOG_CONSOLE_DEBUG << "reader data" << endl; + for (auto e : _objectsCache[objName].vActiveEndpoints) + { + LOG_CONSOLE_DEBUG << e.writeToJsonString() << endl; + } + } + + { + LOG_CONSOLE_DEBUG << "write data" << endl; + for (auto e : _objectsCache[objName].vActiveEndpoints) + { + LOG_CONSOLE_DEBUG << e.writeToJsonString() << endl; + } + } +} -void CDbHandle::addActiveEndPoint(const string& objName, const Int32 port, const Int32 istcp) +void CDbHandle::addActiveEndPoint(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string &nodeName) { -#define LOCAL_HOST "127.0.0.1" +//#define LOCAL_HOST "127.0.0.1" ObjectsCache objectsCache; EndpointF endPoint; - endPoint.host = LOCAL_HOST; + endPoint.host = host; endPoint.port = port; endPoint.timeout = 30000; endPoint.istcp = istcp; + endPoint.nodeName = nodeName; //endPoint.setId = setName + "." + setArea + "." + setGroup; objectsCache[objName].vActiveEndpoints.push_back(endPoint); updateActiveObjectsCache(objectsCache, false); } -void CDbHandle::addEndPointbySet(const string& objName, const Int32 port, const Int32 istcp, const string& setName, const string& setArea, const string& setGroup) +void CDbHandle::addEndPointbySet(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string& setName, const string& setArea, const string& setGroup) { -#define LOCAL_HOST "127.0.0.1" +//#define LOCAL_HOST "127.0.0.1" ObjectsCache objectsCache; EndpointF endPoint; - endPoint.host = LOCAL_HOST; + endPoint.host = host; endPoint.port = port; endPoint.timeout = 30000; endPoint.istcp = istcp; @@ -411,12 +437,12 @@ void CDbHandle::addEndPointbySet(const string& objName, const Int32 port, const } } -void CDbHandle::addActiveWeight1EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName) +void CDbHandle::addActiveWeight1EndPoint(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string& setName) { -#define LOCAL_HOST "127.0.0.1" +//#define LOCAL_HOST "127.0.0.1" ObjectsCache objectsCache; EndpointF endPoint; - endPoint.host = LOCAL_HOST; + endPoint.host = host; endPoint.port = port; endPoint.timeout = 30000; endPoint.istcp = istcp; @@ -427,12 +453,12 @@ void CDbHandle::addActiveWeight1EndPoint(const string& objName, const Int32 port updateActiveObjectsCache(objectsCache, false); } -void CDbHandle::addInActiveWeight1EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName) +void CDbHandle::addInActiveWeight1EndPoint(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string& setName) { -#define LOCAL_HOST "127.0.0.1" +//#define LOCAL_HOST "127.0.0.1" ObjectsCache objectsCache; EndpointF endPoint; - endPoint.host = LOCAL_HOST; + endPoint.host = host; endPoint.port = port; endPoint.timeout = 30000; endPoint.istcp = istcp; @@ -444,12 +470,12 @@ void CDbHandle::addInActiveWeight1EndPoint(const string& objName, const Int32 po } -void CDbHandle::addActiveWeight2EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName) +void CDbHandle::addActiveWeight2EndPoint(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string& setName) { -#define LOCAL_HOST "127.0.0.1" +//#define LOCAL_HOST "127.0.0.1" ObjectsCache objectsCache; EndpointF endPoint; - endPoint.host = LOCAL_HOST; + endPoint.host = host; endPoint.port = port; endPoint.timeout = 30000; endPoint.istcp = istcp; @@ -461,15 +487,16 @@ void CDbHandle::addActiveWeight2EndPoint(const string& objName, const Int32 port } -void CDbHandle::addInactiveEndPoint(const string& objName, const Int32 port, const Int32 istcp) +void CDbHandle::addInactiveEndPoint(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string &nodeName) { -#define LOCAL_HOST "127.0.0.1" +//#define LOCAL_HOST "127.0.0.1" ObjectsCache objectsCache; EndpointF endPoint; - endPoint.host = LOCAL_HOST; + endPoint.host = host; endPoint.port = port; endPoint.timeout = 30000; endPoint.istcp = istcp; + endPoint.nodeName = nodeName; //endPoint.setId = setName; objectsCache[objName].vInactiveEndpoints.push_back(endPoint); updateInactiveObjectsCache(objectsCache, false); @@ -478,14 +505,28 @@ void CDbHandle::addInactiveEndPoint(const string& objName, const Int32 port, con void CDbHandle::cleanEndPoint() { - ObjectsCache objectsCache; + ObjectsCache objectsCache = _objectsCache; + + //从objectsCache删除不是tars的服务 + for (auto it = objectsCache.begin(); it != objectsCache.end();) + { + if (it->first.find("tars.") == string::npos) + { + objectsCache.erase(it++); + } + else + { + ++it; + } + } updateObjectsCache(objectsCache, true); } int CDbHandle::getGroupId(const string& ip) { - map& groupIdMap = _groupIdMap.getReaderData(); + std::lock_guard lock(_mutex); + map& groupIdMap = _groupIdMap; map::iterator it = groupIdMap.find(ip); if (it != groupIdMap.end()) { @@ -554,7 +595,7 @@ void CDbHandle::InsertSetRecord(const string& objName, const string& setName, co setDivisionCache[objName][setName].push_back(setServerInfo); setServerInfo.bActive = false; - setServerInfo.epf.port = 10204; +// setServerInfo.epf.port = 10204; setDivisionCache[objName][setName].push_back(setServerInfo); @@ -582,7 +623,7 @@ void CDbHandle::InsertSetRecord4Inactive(const string& objName, const string& se void CDbHandle::updateDivisionCache(SetDivisionCache& setDivisionCache,bool updateAll) { - //ȫ������ + std::lock_guard lock(_mutex); if(updateAll) { if (setDivisionCache.size() == 0) @@ -601,89 +642,23 @@ void CDbHandle::updateDivisionCache(SetDivisionCache& setDivisionCache,bool upda } } } - _setDivisionCache.getWriterData() = setDivisionCache; - _setDivisionCache.swap(); + _setDivisionCache = setDivisionCache; } else { - _setDivisionCache.getWriterData() = _setDivisionCache.getReaderData(); - SetDivisionCache& tmpsetCache = _setDivisionCache.getWriterData(); + SetDivisionCache& tmpsetCache = _setDivisionCache; SetDivisionCache::const_iterator it = setDivisionCache.begin(); for(;it != setDivisionCache.end();it++) { - //��set��Ϣ�Ÿ��� if(it->second.size() > 0) { tmpsetCache[it->first] = it->second; } else if(tmpsetCache.count(it->first)) { - //�����������нڵ㶼û������set��ɾ�������е�set��Ϣ tmpsetCache.erase(it->first); } } - - _setDivisionCache.swap(); - } -} -#if 0 - -void CDbHandle::updateCpuLoadInfo(vector &vEndpointF) -{ - CpuLoadCache &cpuLoadCacheMap = _cpuLoadCacheMap.getReaderData(); - for(size_t i = 0; i < vEndpointF.size(); ++i) - { - map::const_iterator const_it_cpu = cpuLoadCacheMap.find(vEndpointF[i].host); - if(const_it_cpu != cpuLoadCacheMap.end()) - { - struct tm tb; - int ret = TC_Common::str2tm(const_it_cpu->second.sHeartTime, "%Y-%m-%d %H:%M:%S", tb); - if(ret == 0) - { - vEndpointF[i].cpuload = const_it_cpu->second.iCpuLoad; - vEndpointF[i].sampletime = mktime(&tb); - } - else - { - vEndpointF[i].cpuload = -1; - vEndpointF[i].sampletime = 0; - } - } - else - { - vEndpointF[i].cpuload = -1; - vEndpointF[i].sampletime = 0; - } - } -} - -void CDbHandle::updateCpuLoadInfo(vector &vSetServerInfo) -{ - CpuLoadCache &cpuLoadCacheMap = _cpuLoadCacheMap.getReaderData(); - for(size_t i = 0; i < vSetServerInfo.size(); ++i) - { - map::const_iterator const_it_cpu = cpuLoadCacheMap.find(vSetServerInfo[i].epf.host); - if(const_it_cpu != cpuLoadCacheMap.end()) - { - struct tm tb; - int ret = TC_Common::str2tm(const_it_cpu->second.sHeartTime, "%Y-%m-%d %H:%M:%S", tb); - if(ret == 0) - { - vSetServerInfo[i].epf.cpuload = const_it_cpu->second.iCpuLoad; - vSetServerInfo[i].epf.sampletime = mktime(&tb); - } - else - { - vSetServerInfo[i].epf.cpuload = -1; - vSetServerInfo[i].epf.sampletime = 0; - } - } - else - { - vSetServerInfo[i].epf.cpuload = -1; - vSetServerInfo[i].epf.sampletime = 0; - } } } -#endif diff --git a/unit-test/server/framework/DbHandle.h b/mock/DbHandle.h similarity index 77% rename from unit-test/server/framework/DbHandle.h rename to mock/DbHandle.h index 01761695..0b83ad3d 100755 --- a/unit-test/server/framework/DbHandle.h +++ b/mock/DbHandle.h @@ -1,7 +1,6 @@ - -#ifndef __DB_HANDLE_H__ -#define __DB_HANDLE_H__ + +#pragma once #include "util/tc_common.h" #include "util/tc_config.h" @@ -12,12 +11,15 @@ #include #include "servant/RemoteLogger.h" #include "servant/EndpointF.h" -#include "RegistryDescriptor.h" using namespace tars; -////////////////////////////////////////////////////// -// + +namespace tars +{ + struct ObjectItem; +} typedef map ObjectsCache; + ////////////////////////////////////////////////////// /** * 数据库操作类 @@ -160,38 +162,36 @@ class CDbHandle */ static string Ip2StarStr(uint32_t ip); - static void updateObjectsCache(const ObjectsCache& objCache, bool updateAll); - - static void updateActiveObjectsCache(const ObjectsCache& objCache, bool updateAll); - - static void updateInactiveObjectsCache(const ObjectsCache& objCache, bool updateAll); - - static void updateDivisionCache(SetDivisionCache& setDivisionCache,bool updateAll); - - static void updateCpuLoadInfo(vector &vEndpointF); - - static void updateCpuLoadInfo(vector &vSetServerInfo); - static void InsertSetRecord(const string& objName, const string& setName, const string& setArea, const string& setGroup, EndpointF epf); - static void InsertSetRecord4Inactive(const string& objName, const string& setName, const string& setArea, const string& setGroup, EndpointF epf); - static void addActiveEndPoint(const string& objName, const Int32 port, const Int32 istcp); - - static void addInactiveEndPoint(const string& objName, const Int32 port, const Int32 istcp); + static void addActiveEndPoint(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string &nodeName = ""); + + static void addInactiveEndPoint(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string &nodeName = ""); - static void addEndPointbySet(const string& objName, const Int32 port, const Int32 istcp, const string& setName, const string& setArea, const string& setGroup); + static void addEndPointbySet(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string& setName, const string& setArea, const string& setGroup); - static void addActiveWeight1EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName = ""); + static void addActiveWeight1EndPoint(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string& setName = ""); - static void addInActiveWeight1EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName = ""); + static void addInActiveWeight1EndPoint(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string& setName = ""); - static void addActiveWeight2EndPoint(const string& objName, const Int32 port, const Int32 istcp, const string& setName = ""); + static void addActiveWeight2EndPoint(const string& objName, const string &host, const Int32 port, const Int32 istcp, const string& setName = ""); - static void cleanEndPoint();; + static void cleanEndPoint(); + + static void printActiveEndPoint(const string& objName); + protected: + static void updateObjectsCache(const ObjectsCache& objCache, bool updateAll); + + static void updateActiveObjectsCache(const ObjectsCache& objCache, bool updateAll); + + static void updateInactiveObjectsCache(const ObjectsCache& objCache, bool updateAll); + + static void updateDivisionCache(SetDivisionCache& setDivisionCache,bool updateAll); + /** * 根据group id获取Endpoint */ @@ -201,14 +201,12 @@ class CDbHandle protected: - static TC_ReadersWriterData _objectsCache; + static std::mutex _mutex; //set划分缓存 - static TC_ReadersWriterData _setDivisionCache; + static SetDivisionCache _setDivisionCache; //优先级的序列 - static TC_ReadersWriterData > _mapGroupPriority; + static std::map _mapGroupPriority; //分组信息 - static TC_ReadersWriterData > _groupIdMap; - static TC_ReadersWriterData > _groupNameMap; + static map _groupIdMap; }; -#endif diff --git a/mock/FrameworkServer.cpp b/mock/FrameworkServer.cpp new file mode 100755 index 00000000..806f2904 --- /dev/null +++ b/mock/FrameworkServer.cpp @@ -0,0 +1,129 @@ +#include "mock/FrameworkServer.h" +#include "mock/QueryImp.h" +#include "mock/ConfigImp.h" +#include "mock/QueryImp.h" +#include "mock/StatImp.h" +#include "mock/LogImp.h" +#include "mock/framework.h" + +using namespace std; + +vector> _clientStatData; +vector> _serverStatData; + +FrameworkServer::~FrameworkServer() +{ + +} + +void +FrameworkServer::initialize() +{ + CDbHandle::addActiveEndPoint("tars.tarsmock.ConfigObj", "127.0.0.1", 11003, 1); + CDbHandle::addActiveEndPoint("tars.tarsmock.QueryObj", "127.0.0.1", 17890, 1); + CDbHandle::addActiveEndPoint("tars.tarsmock.LogObj", "127.0.0.1", 11005, 1); + CDbHandle::addActiveEndPoint("tars.tarsmock.StatObj", "127.0.0.1", 12004, 1); + + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".ConfigObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".QueryObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".StatObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".LogObj"); + + string s; + loadLogFormat("","",s); + + //日志路径 + g_globe._log_path = _conf["/tars/log"]; + + //启动写线程 + g_globe._group.start(TC_Common::strto(_conf["/tars/log"])); + + string prefix = TC_Common::lower(_conf.get("/tars/log","true")); + g_globe._bIpPrefix = (prefix == "true") ? true : false; + + //增加对象 + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".LogObj"); + + TARS_ADD_ADMIN_CMD_NORMAL("reloadLogFormat", FrameworkServer::loadLogFormat); +} + + +bool FrameworkServer::loadLogFormat(const string& command, const string& params, string& result) +{ + TLOGDEBUG("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << endl); + + try + { + TC_Config conf; + + conf.parseString(MOCK_FRAMEWORK_CONFIG); + + vector vHourlist; + + map mLogType; + + try + { + string sHour = conf["/tars/log/format"]; + + vHourlist = TC_Common::sepstr(sHour,"|;,"); + + sort(vHourlist.begin(),vHourlist.end()); + + unique(vHourlist.begin(),vHourlist.end()); + + result = "loadLogFormat succ:" + sHour; + + TLOGDEBUG("FrameworkServer::loadLogFormat result:" << result << endl); + + DLOG<< "FrameworkServer::loadLogFormat result:" << result << endl; + + //hour=app.server.file|app2.server2.file2 + map mType; + if(conf.getDomainMap("/tars/log/logtype", mType)) + { + map::iterator it = mType.begin(); + while(it != mType.end()) + { + vector vList = TC_Common::sepstr(it->second,"|;,"); + for(size_t i = 0;i < vList.size();i++) + { + //app.server.file = hour + mLogType[vList[i]] = it->first; + + TLOGDEBUG("FrameworkServer::loadLogFormat " << vList[i] << "|" << it->first << endl); + + DLOG<<"FrameworkServer::loadLogFormat " << vList[i] << "|" << it->first << endl; + } + it++; + } + } + + g_globe.update(vHourlist, mLogType); + + } + catch(exception& e) + { + result += e.what(); + TLOGERROR("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << "|result:" << result << endl); + } + + return true; + } + catch(exception &e) + { + result += e.what(); + TLOGERROR("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << "|result:" << result << endl); + } + + return false; +} + +void FrameworkServer::destroyApp() +{ +} + +void FrameworkServer::run() +{ + this->waitForShutdown(); +} \ No newline at end of file diff --git a/mock/FrameworkServer.h b/mock/FrameworkServer.h new file mode 100755 index 00000000..20081c4e --- /dev/null +++ b/mock/FrameworkServer.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include "servant/Application.h" + +using namespace tars; + +extern vector> _clientStatData; +extern vector> _serverStatData; + +class FrameworkServer : public Application, public TC_Thread +{ +public: + /** + * 析构函数 + **/ + virtual ~FrameworkServer(); + + /** + * 服务初始化 + **/ + virtual void initialize(); + + /** + * 服务销毁 + **/ + virtual void destroyApp(); + +protected: + virtual void run(); + + + bool loadLogFormat(const string& command, const string& params, string& result); +}; + + diff --git a/unit-test/server/framework/LogImp.cpp b/mock/LogImp.cpp similarity index 100% rename from unit-test/server/framework/LogImp.cpp rename to mock/LogImp.cpp diff --git a/unit-test/server/framework/LogImp.h b/mock/LogImp.h similarity index 100% rename from unit-test/server/framework/LogImp.h rename to mock/LogImp.h diff --git a/unit-test/server/framework/QueryImp.cpp b/mock/QueryImp.cpp similarity index 97% rename from unit-test/server/framework/QueryImp.cpp rename to mock/QueryImp.cpp index 271abec8..c66e3e4c 100755 --- a/unit-test/server/framework/QueryImp.cpp +++ b/mock/QueryImp.cpp @@ -1,13 +1,11 @@ - -#include "QueryImp.h" -#include "util/tc_logger.h" + +#include "mock/QueryImp.h" #include "util/tc_clientsocket.h" void QueryImp::initialize() { TLOGDEBUG("begin QueryImp init"< QueryImp::findObjectById(const string & id, tars::CurrentPtr current) @@ -34,11 +32,13 @@ tars::Int32 QueryImp::findObjectById4Any(const std::string & id,vector &activeEp,vector &inactiveEp,tars::CurrentPtr current) { - LOG_CONSOLE_DEBUG << endl; +// LOG_CONSOLE_DEBUG << endl; ostringstream os; int iRet = _db.findObjectByIdInGroupPriority(id,current->getIp(),activeEp, inactiveEp,os); +// LOG_CONSOLE_DEBUG << id << ", " << activeEp.size() << endl; + doDaylog(FUNID_findObjectById4All,id,activeEp,inactiveEp,current,os); return iRet; @@ -46,7 +46,7 @@ int QueryImp::findObjectById4All(const std::string & id, vector int QueryImp::findObjectByIdInSameGroup(const std::string & id, vector &activeEp,vector &inactiveEp, tars::CurrentPtr current) { - LOG_CONSOLE_DEBUG << endl; +// LOG_CONSOLE_DEBUG << endl; ostringstream os; TLOGINFO(__FUNCTION__ << ":" << __LINE__ << "|" << id << "|" << current->getIp() << endl); diff --git a/unit-test/server/framework/QueryImp.h b/mock/QueryImp.h similarity index 67% rename from unit-test/server/framework/QueryImp.h rename to mock/QueryImp.h index 7b662102..dcfe7ed0 100755 --- a/unit-test/server/framework/QueryImp.h +++ b/mock/QueryImp.h @@ -1,6 +1,6 @@ - -#ifndef __QUERY_IMP_H__ -#define __QUERY_IMP_H__ + +#pragma once + #include "servant/QueryF.h" #include "DbHandle.h" @@ -41,6 +41,15 @@ class QueryImp: public QueryF */ virtual void destroy() {}; + /** + * + * @param id + * @param nodeName + * @param _current_ + * @return + */ + virtual tars::Int32 findObjectNodeName(const std::string & id,vector &nodeName,tars::TarsCurrentPtr current) { return -1; } + /** * 根据id获取所有该对象的活动endpoint列表 */ @@ -70,6 +79,29 @@ class QueryImp: public QueryF * 根据id获取对象同set endpoint列表 */ Int32 findObjectByIdInSameSet(const std::string & id,const std::string & setId,vector &activeEp,vector &inactiveEp, tars::CurrentPtr current); + + /** 注册id变化的通知, 通知时会通知所有的变化内容(企业版功能) + * + * @param ids 对象名称 + * @param name 当前模块名称 + * @return: 0-成功 others-失败 + */ + Int32 registerChange(const map & heartbeat, const string &name, CurrentPtr current) { return -1; }; + + /** 注册id变化的通知, 通知时后需要自己主动find(企业版功能) + * + * @param id 对象名称 + * @param name 当前模块名称 + * @return: 0-成功 others-失败 + */ + Int32 registerQuery(const string &id, const string &name, CurrentPtr current) { return -1; }; + + /** + * 获取锁, 实现业务服务一主多备的模式(企业版功能) + * @return 0: 获取锁成功; 1:获取锁失败; 2: 数据异常, -1:其他异常 + */ + Int32 getLocker(const tars::GetMasterSlaveLock &req, CurrentPtr current) { return -1;}; + private: /** * 打印按天日志 @@ -85,4 +117,3 @@ class QueryImp: public QueryF CDbHandle _db; }; -#endif diff --git a/unit-test/server/framework/StatImp.cpp b/mock/StatImp.cpp similarity index 95% rename from unit-test/server/framework/StatImp.cpp rename to mock/StatImp.cpp index ad98b4bd..85ff5f88 100644 --- a/unit-test/server/framework/StatImp.cpp +++ b/mock/StatImp.cpp @@ -1,7 +1,7 @@  #include "StatImp.h" -#include "../FrameworkServer.h" +#include "FrameworkServer.h" /////////////////////////////////////////////////////////// // diff --git a/unit-test/server/framework/StatImp.h b/mock/StatImp.h similarity index 100% rename from unit-test/server/framework/StatImp.h rename to mock/StatImp.h diff --git a/mock/TarsMockUtil.cpp b/mock/TarsMockUtil.cpp new file mode 100644 index 00000000..93d808e5 --- /dev/null +++ b/mock/TarsMockUtil.cpp @@ -0,0 +1,51 @@ +// +// Created by jarod on 2024/3/6. +// + +#include "mock/TarsMockUtil.h" +#include "mock/FrameworkServer.h" +#include "mock/framework.h" + +TarsMockUtil::TarsMockUtil() +{ + _fs = std::make_shared(); +} + +void TarsMockUtil::startFramework() +{ + _fs->main(MOCK_FRAMEWORK_CONFIG); + _fs->start(); + _fs->waitForReady(); +} + +void TarsMockUtil::stopFramework() +{ + _fs->terminate(); +} + +std::shared_ptr TarsMockUtil::getFrameworkServer() +{ + return _fs; +} + +void TarsMockUtil::refreshRegistry(const string &obj, size_t count) +{ + do + { + TC_Common::sleep(1); + + vector activeEp; + vector inactiveEp; + + _fs->getApplicationCommunicator()->getLocatorPrx()->findObjectById4All(obj, activeEp, inactiveEp); + + auto eps1 = EndpointInfo::toNodeEndpointF(activeEp); + + if(eps1.size() == count) + { + break; + } + + }while(true); +} + diff --git a/mock/TarsMockUtil.h b/mock/TarsMockUtil.h new file mode 100644 index 00000000..d8a262d6 --- /dev/null +++ b/mock/TarsMockUtil.h @@ -0,0 +1,47 @@ +// +// Created by jarod on 2024/3/6. +// + +#pragma once + +#include +#include +#include "servant/Application.h" +#include "mock/FrameworkServer.h" + +class FrameworkServer; + +class TarsMockUtil +{ +public: + TarsMockUtil(); + + /** + * 启动framework + * @param fs + */ + void startFramework(); + + /** + * 停止framework + * @param fs + */ + void stopFramework(); + + /** + * 等待主控返回count个服务 + * @param obj + * @param count + */ + void refreshRegistry(const std::string &obj, size_t count); + + /** + * + * @return + */ + std::shared_ptr getFrameworkServer(); + +protected: + std::shared_ptr _fs; +}; + diff --git a/unit-test/server/framework.conf b/mock/framework.h old mode 100755 new mode 100644 similarity index 75% rename from unit-test/server/framework.conf rename to mock/framework.h index 5ca3a9ff..e75480f1 --- a/unit-test/server/framework.conf +++ b/mock/framework.h @@ -1,129 +1,144 @@ - - - #proxy需要的配置 - - #地址 - locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004 - #最大超时时间(毫秒) - sync-invoke-timeout = 5000 - async-invoke-timeout = 60000 - #刷新端口时间间隔(毫秒) - refresh-endpoint-interval = 5000 - #模块间调用[可选] - stat = TestApp.FrameworkServer.StatObj - #发送队列长度 - sendqueuelimit = 1000000 - #异步回调队列个数限制 - asyncqueuecap = 1000000 - #网络异步回调线程个数 - asyncthread = 3 - #网络线程个数 - netthread = 2 - #合并回调线程和网络线程(以网络线程个数为准) - mergenetasync = 0 - #模块名称 - modulename = TestApp.FrameworkServer - - - - #定义所有绑定的IP - - start_output = ERROR - closecout = 0 - #应用名称 - app = TestApp - #服务名称 - server = FrameworkServer - #服务的数据目录,可执行文件,配置文件等 - basepath = . - datapath = . - #日志路径 - logpath = . - #网络线程个数 - netthread = 1 - #合并网络和业务线程(以网络线程个数为准) - mergenetimp = 0 - opencoroutine = 0 - loglevel=TARS - - #本地管理套接字[可选] - local = tcp -h 127.0.0.1 -p 15701 -t 10000 - - #本地node的ip:port:timeout[可选] -# node = ServerObj@tcp -h 127.0.0.1 -p 2345 -t 10000 - #配置中心的地址[可选] - config = TestApp.FrameworkServer.ConfigObj - #配置中心的地址[可选] -# notify = tars.tarsconfig.NotifyObj - #远程LogServer[可选] - log = TestApp.FrameworkServer.LogObj - - - #ip:port:timeout - endpoint = tcp -h 127.0.0.1 -p 11003 -t 60000 - #allow ip - allow = - #max connection num - maxconns = 4096 - #imp thread num - threads = 5 - #servant - servant = TestApp.FrameworkServer.ConfigObj - #queue capacity - queuecap = 1000000 - - - - #ip:port:timeout - endpoint = tcp -h 127.0.0.1 -p 11005 -t 60000 - #allow ip - allow = - #max connection num - maxconns = 4096 - #imp thread num - threads = 5 - #servant - servant = TestApp.FrameworkServer.LogObj - #queue capacity - queuecap = 1000000 - - - - #ip:port:timeout - endpoint = tcp -h 127.0.0.1 -p 11004 -t 60000 - #allow ip - allow = - #max connection num - maxconns = 4096 - #imp thread num - threads = 5 - #servant - servant = TestApp.FrameworkServer.QueryObj - #queue capacity - queuecap = 1000000 - - - - #ip:port:timeout - endpoint = tcp -h 127.0.0.1 -p 12004 -t 60000 - #allow ip - allow = - #max connection num - maxconns = 4096 - #imp thread num - threads = 5 - #servant - servant = TestApp.FrameworkServer.StatObj - #queue capacity - queuecap = 1000000 - - - - - - logpath = . - logthread = 1 - ipfix = true - - - +#pragma once + +#include + +const static std::string &MOCK_FRAMEWORK_CONFIG = R"( + + + #proxy需要的配置 + + #地址 + locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890 + #最大超时时间(毫秒) + sync-invoke-timeout = 5000 + async-invoke-timeout = 60000 + #刷新端口时间间隔(毫秒) + refresh-endpoint-interval = 5000 + #模块间调用[可选] + stat = tars.tarsmock.StatObj + #发送队列长度 + sendqueuelimit = 100000 + #异步回调队列个数限制 + asyncqueuecap = 100000 + #网络异步回调线程个数 + asyncthread = 3 + #网络线程个数 + netthread = 2 + #合并回调线程和网络线程(以网络线程个数为准) + mergenetasync = 0 + #模块名称 + modulename = tars.tarsmock + + + + #定义所有绑定的IP + + start_output = ERROR + closecout = 0 + #应用名称 + app = tars + #服务名称 + server = tarsmock + #服务的数据目录,可执行文件,配置文件等 + basepath = . + datapath = . + #日志路径 + logpath = . + #网络线程个数 + netthread = 1 + #合并网络和业务线程(以网络线程个数为准) + mergenetimp = 0 + opencoroutine = 0 + loglevel=TARS + + #本地管理套接字[可选] + local = tcp -h 127.0.0.1 -p 15791 -t 10000 + + #本地node的ip:port:timeout[可选] +# node = ServerObj@tcp -h 127.0.0.1 -p 2345 -t 10000 + #配置中心的地址[可选] + config = tars.tarsmock.ConfigObj + #配置中心的地址[可选] +# notify = tars.tarsconfig.NotifyObj + #远程LogServer[可选] + log = tars.tarsmock.LogObj + + + #ip:port:timeout + endpoint = tcp -h 127.0.0.1 -p 11003 -t 60000 + #allow ip + allow = + #max connection num + maxconns = 4096 + #imp thread num + threads = 5 + #servant + servant = tars.tarsmock.ConfigObj + #queue capacity + queuecap = 1000000 + + + + #ip:port:timeout + endpoint = tcp -h 127.0.0.1 -p 11005 -t 60000 + #allow ip + allow = + #max connection num + maxconns = 4096 + #imp thread num + threads = 5 + #servant + servant = tars.tarsmock.LogObj + #queue capacity + queuecap = 1000000 + + + + #ip:port:timeout + endpoint = tcp -h 127.0.0.1 -p 17890 -t 60000 + #allow ip + allow = + #max connection num + maxconns = 4096 + #imp thread num + threads = 5 + #servant + servant = tars.tarsmock.QueryObj + #queue capacity + queuecap = 1000000 + + + + #ip:port:timeout + endpoint = tcp -h 127.0.0.1 -p 12004 -t 60000 + #allow ip + allow = + #max connection num + maxconns = 4096 + #imp thread num + threads = 5 + #servant + servant = tars.tarsmock.StatObj + #queue capacity + queuecap = 1000000 + + + + + + logpath = . + logthread = 1 + ipfix = true + + hour=app.server.file|app2.server2.file2 + + + app.server.file = hour + + + + + +)"; + + diff --git a/servant/CMakeLists.txt b/servant/CMakeLists.txt index 09e034ef..eec543f4 100644 --- a/servant/CMakeLists.txt +++ b/servant/CMakeLists.txt @@ -41,8 +41,8 @@ macro(complice_tars OUT_DEPENDS_LIST HEADER INCLUDE) OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${TARS_H} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS tars2cpp ${FILE} - COMMAND ${TARS2CPP} --with-tars --without-trace ${HEADER_STRING} ${INCLUDE_STRING} ${TARS_IN} - COMMENT "${TARS2CPP} --with-tars --without-trace ${HEADER_STRING} ${INCLUDE_STRING} ${TARS_IN}") + COMMAND ${TARS2CPP} --with-tars ${HEADER_STRING} ${INCLUDE_STRING} ${TARS_IN} + COMMENT "${TARS2CPP} --with-tars ${HEADER_STRING} ${INCLUDE_STRING} ${TARS_IN}") list(APPEND DEPENDS_LIST ${CMAKE_CURRENT_SOURCE_DIR}/${TARS_H}) @@ -61,6 +61,8 @@ macro(complice_tars OUT_DEPENDS_LIST HEADER INCLUDE) endmacro() +configure_file(${PROJECT_SOURCE_DIR}/makefile/tars-tools.cmake.in ${PROJECT_SOURCE_DIR}/makefile/tars-tools.cmake @ONLY) + add_subdirectory(protocol/servant) add_subdirectory(protocol/framework) add_subdirectory(tup) @@ -73,5 +75,6 @@ install(DIRECTORY jmem DESTINATION include) install(DIRECTORY script DESTINATION . PATTERN "*.sh" PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ WORLD_READ WORLD_EXECUTE) -install(DIRECTORY makefile DESTINATION .) +#install(DIRECTORY makefile DESTINATION . EXCLUDE tars-tools.cmake.in ) +install(DIRECTORY makefile DESTINATION . PATTERN tars-tools.cmake.in EXCLUDE) diff --git a/servant/libservant/AdapterProxy.cpp b/servant/libservant/AdapterProxy.cpp index 13792c17..1a79784e 100755 --- a/servant/libservant/AdapterProxy.cpp +++ b/servant/libservant/AdapterProxy.cpp @@ -150,9 +150,9 @@ std::shared_ptr AdapterProxy::onOpensslCallback(TC_Transceiver* tran void AdapterProxy::onCloseCallback(TC_Transceiver* trans, TC_Transceiver::CloseReason reason, const string &err) { - if(_objectProxy->getRootServantProxy()->tars_get_push_callback()) + if(auto cb = _objectProxy->getRootServantProxy()->tars_get_push_callback()) { - _objectProxy->getRootServantProxy()->tars_get_push_callback()->onClose(trans->getConnectEndpoint()); + cb->onClose(trans->getConnectEndpoint()); } int millisecond =_objectProxy->reconnect(); @@ -287,15 +287,18 @@ TC_NetWorkBuffer::PACKET_TYPE AdapterProxy::onVerifyAuthCallback(TC_NetWorkBuffe void AdapterProxy::initStatHead() { vector vtSetInfo; - if(!ClientConfig::SetDivision.empty() && StatReport::divison2SetInfo(ClientConfig::SetDivision, vtSetInfo)) { + + if(!_communicator->getClientConfig().SetDivision.empty() && StatReport::divison2SetInfo(_communicator->getClientConfig().SetDivision, vtSetInfo)) { //主调(client)启用set - _statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "." + vtSetInfo[0] + vtSetInfo[1] + vtSetInfo[2] + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN); + _statHead.masterName = StatReport::trimAndLimitStr(_communicator->getClientConfig().ModuleName + "." + vtSetInfo[0] + vtSetInfo[1] + vtSetInfo[2] + "@" + _communicator->getClientConfig().TarsVersion, StatReport::MAX_MASTER_NAME_LEN); } else { - _statHead.masterName = StatReport::trimAndLimitStr(ClientConfig::ModuleName + "@" + ClientConfig::TarsVersion, StatReport::MAX_MASTER_NAME_LEN); + _statHead.masterName = StatReport::trimAndLimitStr(_communicator->getClientConfig().ModuleName + "@" + _communicator->getClientConfig().TarsVersion, StatReport::MAX_MASTER_NAME_LEN); } + _statHead.masterIp = _communicator->getClientConfig().NodeName; + string sSlaveSet = _ep.setDivision(); const string sSlaveName = getSlaveName(_objectProxy->name()); @@ -374,6 +377,7 @@ int AdapterProxy::invoke_connection_serial(ReqMessage * msg) _requestMsg = NULL; msg->eStatus = ReqMessage::REQ_EXC; + msg->response->iRet = TARSSENDREQUESTERR; finishInvoke(msg); @@ -441,6 +445,7 @@ int AdapterProxy::invoke_connection_parallel(ReqMessage * msg) //发送出错了 msg->eStatus = ReqMessage::REQ_EXC; + msg->response->iRet = TARSSENDREQUESTERR; finishInvoke(msg); @@ -826,8 +831,9 @@ void AdapterProxy::finishInvoke_parallel(shared_ptr & rsp) if (rsp->iRequestId == 0) { + auto cb = _objectProxy->getRootServantProxy()->tars_get_push_callback(); //requestid 为0 是push消息, push callback is null - if (!_objectProxy->getRootServantProxy()->tars_get_push_callback()) + if (!cb) { TLOGERROR("[AdapterProxy::finishInvoke(BasePacket), request id is 0, pushcallback is null, " << _objectProxy->name() << ", " << _trans->getConnectionString() << "]" << endl); throw TarsDecodeException("request id is 0, pushcallback is null, obj: " + _objectProxy->name() + ", desc: " + _trans->getConnectionString()); @@ -840,7 +846,7 @@ void AdapterProxy::finishInvoke_parallel(shared_ptr & rsp) msg->proxy = _objectProxy->getServantProxy(); msg->pObjectProxy = _objectProxy; msg->adapter = this; - msg->callback = _objectProxy->getRootServantProxy()->tars_get_push_callback(); + msg->callback = cb; } else { @@ -1049,7 +1055,9 @@ void AdapterProxy::doKeepAlive() TLOGTARS("[AdapterProxy::doKeepAlive, " << _objectProxy->name() << ", " << _trans->getConnectionString() << "]" << endl); ReqMessage *msg = new ReqMessage(); - ServantProxyCallbackPtr callback = new PingCallback(); +// ServantProxyCallbackPtr callback = new PingCallback(); + ServantProxyCallbackPtr callback (new PingCallback()); + callback->setServantPrx(_objectProxy->getServantProxy()); msg->init(ReqMessage::ASYNC_CALL, _objectProxy->getServantProxy()); msg->callback = callback; diff --git a/servant/libservant/AdminServant.cpp b/servant/libservant/AdminServant.cpp index 58def34a..f024cbfd 100644 --- a/servant/libservant/AdminServant.cpp +++ b/servant/libservant/AdminServant.cpp @@ -15,9 +15,11 @@ */ #include "util/tc_platform.h" #include "servant/AdminServant.h" -#include "servant/Application.h" #include "servant/NotifyObserver.h" #include "servant/ServantHelper.h" +#include "servant/RemoteNotify.h" +#include "servant/RemoteLogger.h" +#include "servant/Application.h" namespace tars { @@ -42,6 +44,8 @@ void AdminServant::shutdown(CurrentPtr current) { TLOGERROR("[TARS][AdminServant::shutdown] from node" << endl); + _application->getApplicationCommunicator()->terminate(); + _application->terminate(); #if TARGET_PLATFORM_WINDOWS HANDLE hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId()); if (hProcess == NULL) @@ -63,5 +67,10 @@ string AdminServant::notify(const string &command, CurrentPtr current) return this->getApplication()->getNotifyObserver()->notify(command, current); } +tars::Int64 AdminServant::getPid(CurrentPtr current) +{ + return getpid(); +} + /////////////////////////////////////////////////////////////////////// } diff --git a/servant/libservant/AppCache.cpp b/servant/libservant/AppCache.cpp index 17de3824..eebe2f09 100644 --- a/servant/libservant/AppCache.cpp +++ b/servant/libservant/AppCache.cpp @@ -28,6 +28,10 @@ void AppCache::setCacheInfo(const string &sFile,int32_t iSynInterval) { TC_LockT lock(*this); + if(!_file.empty()) + { + return; + } string sPath = TC_File::extractFilePath(sFile); TC_File::makeDirRecursive(sPath); @@ -115,7 +119,7 @@ int AppCache::set(const string &sName,const string &sValue,const string sDomain) if(_lastSynTime == 0) //第一次写数据 打印tarsversion { m.clear(); - m["tarsversion"] = ClientConfig::TarsVersion; + m["tarsversion"] = TARS_VERSION; tConf.insertDomainParam(string(APPCACHE_ROOT_PATH),m,true); } diff --git a/servant/libservant/Application.cpp b/servant/libservant/Application.cpp index e9ad500c..e7e24578 100644 --- a/servant/libservant/Application.cpp +++ b/servant/libservant/Application.cpp @@ -26,8 +26,13 @@ #include "servant/NotifyObserver.h" #include "servant/AuthLogic.h" #include "servant/CommunicatorFactory.h" +#include "servant/StatReport.h" +#include "servant/RemoteLogger.h" +#include "servant/RemoteConfig.h" +#include "servant/RemoteNotify.h" +#include "servant/QueryF.h" -#include +#include #if TARGET_PLATFORM_LINUX #include #endif @@ -54,6 +59,7 @@ namespace tars std::string ServerConfig::TarsPath; //服务路径 std::string ServerConfig::Application; //应用名称 std::string ServerConfig::ServerName; //服务名称,一个服务名称含一个或多个服务标识 +std::string ServerConfig::NodeName; //服务如果部署在框架上, 则表示节点名称, 从模板中获取(framework>=3.0.17才支持), 否则为LocalIp std::string ServerConfig::LocalIp; //本机IP std::string ServerConfig::BasePath; //应用程序路径,用于保存远程系统配置的本地目录 std::string ServerConfig::DataPath; //应用程序路径,用于本地数据 @@ -69,31 +75,69 @@ std::string ServerConfig::LogLevel; //log日志级别 std::string ServerConfig::ConfigFile; //框架配置文件路径 int ServerConfig::ReportFlow = 1; //是否服务端上报所有接口stat流量 0不上报 1上报 (用于非tars协议服务流量统计) int ServerConfig::IsCheckSet = 1; //是否对按照set规则调用进行合法性检查 0,不检查,1检查 -int ServerConfig::OpenCoroutine = 0; //是否启用协程处理方式 +int ServerConfig::OpenCoroutine = 0; //是否启用协程处理方式 size_t ServerConfig::CoroutineMemSize; //协程占用内存空间的最大大小 uint32_t ServerConfig::CoroutineStackSize; //每个协程的栈大小(默认128k) bool ServerConfig::ManualListen = false; //手工启动监听端口 -//bool ServerConfig::MergeNetImp = false; //合并网络和处理线程 int ServerConfig::NetThread = 1; //servernet thread bool ServerConfig::CloseCout = true; int ServerConfig::BackPacketLimit = 0; int ServerConfig::BackPacketMin = 1024; -//int ServerConfig::Pattern = 0; +int ServerConfig::BakFlag = 0; +int ServerConfig::BakType = 0; -#if TARS_SSL std::string ServerConfig::CA; std::string ServerConfig::Cert; std::string ServerConfig::Key; -bool ServerConfig::VerifyClient = false; +bool ServerConfig::VerifyClient = false; std::string ServerConfig::Ciphers; -#endif - map ServerConfig::Context; +ServerBaseInfo ServerConfig::toServerBaseInfo() +{ + ServerBaseInfo serverBaseInfo; + serverBaseInfo.TarsPath = TarsPath; + serverBaseInfo.Application = Application; + serverBaseInfo.ServerName = ServerName; + serverBaseInfo.NodeName = NodeName; + serverBaseInfo.BasePath = BasePath; + serverBaseInfo.DataPath = DataPath; + serverBaseInfo.LocalIp = LocalIp; + serverBaseInfo.LogPath = LogPath; + serverBaseInfo.LogSize = LogSize; + serverBaseInfo.LogNum = LogNum; + serverBaseInfo.LogLevel = LogLevel; + serverBaseInfo.Local = Local; + serverBaseInfo.Node = Node; + serverBaseInfo.Log = Log; + serverBaseInfo.Config = Config; + serverBaseInfo.Notify = Notify; + serverBaseInfo.ConfigFile = ConfigFile; + serverBaseInfo.CloseCout = CloseCout; + serverBaseInfo.ReportFlow = ReportFlow; + serverBaseInfo.IsCheckSet = IsCheckSet; + serverBaseInfo.OpenCoroutine = OpenCoroutine; + serverBaseInfo.CoroutineMemSize = CoroutineMemSize; + serverBaseInfo.CoroutineStackSize = CoroutineStackSize; + serverBaseInfo.NetThread = NetThread; + serverBaseInfo.ManualListen = ManualListen; + serverBaseInfo.BackPacketLimit = BackPacketLimit; + serverBaseInfo.BackPacketMin = BackPacketMin; + serverBaseInfo.BakFlag = BakFlag; + serverBaseInfo.BakType = BakType; + + serverBaseInfo.CA = CA; + serverBaseInfo.Cert = Cert; + serverBaseInfo.Key = Key; + serverBaseInfo.VerifyClient = VerifyClient; + serverBaseInfo.Ciphers = Ciphers; + serverBaseInfo.Context = Context; + + return serverBaseInfo; +} /////////////////////////////////////////////////////////////////////////////////////////// -//TC_Config Application::_conf; -//TC_EpollServerPtr Application::_epollServer = NULL; -CommunicatorPtr Application::_communicator = NULL; + +CommunicatorPtr Application::_communicator = nullptr; PropertyReportPtr g_pReportRspQueue; @@ -120,7 +164,7 @@ Application::~Application() if(_epollServer) { _epollServer->terminate(); - _epollServer = NULL; + _epollServer = nullptr; } #if TARGET_PLATFORM_WINDOWS WSACleanup(); @@ -137,6 +181,11 @@ CommunicatorPtr& Application::getCommunicator() return _communicator; } +CommunicatorPtr& Application::getApplicationCommunicator() +{ + return _applicationCommunicator; +} + void reportRspQueue(TC_EpollServer *epollServer) { if (!g_pReportRspQueue) @@ -153,20 +202,20 @@ void reportRspQueue(TC_EpollServer *epollServer) const vector &adapters = epollServer->getBindAdapters(); size_t n = 0; - for (size_t i = 0; i < adapters.size(); ++i) + for (const auto & adapter : adapters) { - n = n + adapters[i]->getSendBufferSize(); + n = n + adapter->getSendBufferSize(); } g_pReportRspQueue->report((int)n); } } -void heartBeatFunc(const string& adapterName) -{ - TARS_KEEPALIVE(adapterName); -} - +//void heartBeatFunc(const string& adapterName) +//{ +// TARS_KEEPALIVE(adapterName); +//} +// void Application::manualListen() { vector v = getEpollServer()->getBindAdapters(); @@ -183,7 +232,9 @@ void Application::waitForShutdown() _epollServer->setCallbackFunctor(reportRspQueue); - _epollServer->setHeartBeatFunctor(heartBeatFunc); + _epollServer->setHeartBeatFunctor([&](const string &adapter){ + _keepAliveNodeFHelper->keepAlive(adapter); + }); _epollServer->setDestroyAppFunctor([&](TC_EpollServer *epollServer){ @@ -197,7 +248,7 @@ void Application::waitForShutdown() TC_Port::unregisterCtrlC(_ctrlCId); TC_Port::unregisterTerm(_termId); - _epollServer = NULL; + _epollServer = nullptr; } void Application::waitForReady() @@ -212,6 +263,16 @@ void Application::terminate() { if (_epollServer && !_epollServer->isTerminate()) { + if(_masterSlaveCheckThread && _masterSlaveCheckThread->joinable()) + { + { + TC_ThreadLock::Lock lock(_masterSlaveLock); + _terminateCheckMasterSlave = true; + _masterSlaveLock.notify(); + } + + _masterSlaveCheckThread->join(); + } std::this_thread::sleep_for(std::chrono::milliseconds(100)); //稍微休息一下, 让当前处理包能够回复 _epollServer->terminate(); @@ -246,7 +307,7 @@ bool Application::cmdViewStatus(const string& command, const string& params, str bool Application::cmdCloseCoreDump(const string& command, const string& params, string& result) { #if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS - struct rlimit tlimit; + struct rlimit tlimit{}; int ret = 0; ostringstream os; @@ -373,7 +434,6 @@ bool Application::cmdEnableDayLog(const string& command, const string& params, s result = "set " + vParams[0] + " " + vParams[1] + " " + vParams[2] + " ok"; } - if (vParams[0] == "local") { RemoteTimeLogger::getInstance()->enableLocal(sFile, bEnable); @@ -397,7 +457,7 @@ bool Application::cmdLoadConfig(const string& command, const string& params, str string filename = TC_Common::trim(params); - if (RemoteConfig::getInstance()->addConfig(filename, result, false)) + if (_remoteConfig->addConfig(filename, result, false)) { RemoteNotify::getInstance()->report(result); @@ -480,7 +540,7 @@ bool Application::cmdViewBuildID(const string& command, const string& params, st char buildTime[50] = {0}; sprintf(buildTime, "%d.%02d%02d.%06d", YEARSUF, MONTH + 1, DAY, TIMEINT); - result = "$" + ServerConfig::Application + "." + ServerConfig::ServerName + "-" + string(buildTime) + "$"; + result = "$" + _serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + "-" + string(buildTime) + "$"; return true; } @@ -493,30 +553,31 @@ bool Application::cmdLoadProperty(const string& command, const string& params, s //重新解析配置文件 _conf.parseFile(ServerConfig::ConfigFile); - string sResult = ""; + string sResult; //加载通讯器属性 - _communicator->setProperty(_conf); + _applicationCommunicator->setProperty(_conf); - _communicator->reloadProperty(sResult); + _applicationCommunicator->reloadProperty(sResult); //加载远程对象 - ServerConfig::Log = _conf.get("/tars/application/server"); + _serverBaseInfo.Log = _conf.get("/tars/application/server"); +// ServerConfig::Log = _serverBaseInfo.Log; - RemoteTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath,setDivision()); + RemoteTimeLogger::getInstance()->setLogInfo(_applicationCommunicator, _serverBaseInfo.Log, _serverBaseInfo.Application, _serverBaseInfo.ServerName, _serverBaseInfo.LogPath,setDivision()); - ServerConfig::Config = _conf.get("/tars/application/server"); + _serverBaseInfo.Config = _conf.get("/tars/application/server"); - RemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision(), 5); + _remoteConfig->setConfigInfo(_applicationCommunicator, _serverBaseInfo.Config, _serverBaseInfo.Application, _serverBaseInfo.ServerName, _serverBaseInfo.BasePath, setDivision(), 5); - ServerConfig::Notify = _conf.get("/tars/application/server"); + _serverBaseInfo.Notify = _conf.get("/tars/application/server"); - RemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision(), ServerConfig::LocalIp); + RemoteNotify::getInstance()->setNotifyInfo(_applicationCommunicator, _serverBaseInfo.Notify, _serverBaseInfo.Application, _serverBaseInfo.ServerName, setDivision()); result = "loaded config items:\r\n" + sResult + - "log=" + ServerConfig::Log + "\r\n" + - "config=" + ServerConfig::Config + "\r\n" + - "notify=" + ServerConfig::Notify + "\r\n"; + "log=" + _serverBaseInfo.Log + "\r\n" + + "config=" + _serverBaseInfo.Config + "\r\n" + + "notify=" + _serverBaseInfo.Notify + "\r\n"; } catch (TC_Config_Exception & ex) { @@ -603,8 +664,8 @@ bool Application::cmdReloadLocator(const string& command, const string& params, } else { - _communicator->setProperty("locator", sLocator); - _communicator->reloadLocator(); + _applicationCommunicator->setProperty("locator", sLocator); + _applicationCommunicator->reloadLocator(); result = sLocator + " set succ."; } @@ -624,12 +685,12 @@ bool Application::cmdViewResource(const string& command, const string& params, s ostringstream os; - os << _communicator->getResourcesInfo() << endl; + os << _applicationCommunicator->getResourcesInfo() << endl; os << OUT_LINE << endl; vector adapters = _epollServer->getBindAdapters(); - for(auto adapter : adapters) + for(const auto& adapter : adapters) { outAdapter(os, _servantHelper->getAdapterServant(adapter->getName()), adapter); os << TC_Common::outfill("recv-buffer-count") << adapter->getRecvBufferSize() << endl; @@ -647,9 +708,9 @@ void Application::outAllAdapter(ostream &os) { auto m = _epollServer->getListenSocketInfo(); - for (auto it = m.begin(); it != m.end(); ++it) + for (auto & it : m) { - outAdapter(os, _servantHelper->getAdapterServant(it->second->getName()), it->second); + outAdapter(os, _servantHelper->getAdapterServant(it.second->getName()), it.second); os << OUT_LINE << endl; } @@ -659,7 +720,7 @@ bool Application::addConfig(const string &filename) { string result; - if (RemoteConfig::getInstance()->addConfig(filename, result, false)) + if (_remoteConfig->addConfig(filename, result, false)) { RemoteNotify::getInstance()->report(result); @@ -672,11 +733,10 @@ bool Application::addConfig(const string &filename) bool Application::addAppConfig(const string &filename) { - string result = ""; + string result; // true-只获取应用级别配置 - if (RemoteConfig::getInstance()->addConfig(filename, result, true)) - + if (_remoteConfig->addConfig(filename, result, true)) { RemoteNotify::getInstance()->report(result); @@ -709,7 +769,7 @@ void Application::main(const TC_Option &option) //加载配置文件 ServerConfig::ConfigFile = option.getValue("config"); - if (ServerConfig::ConfigFile == "") + if (ServerConfig::ConfigFile.empty()) { cerr << "start server with config, for example: exe --config=config.conf" << endl; @@ -718,17 +778,14 @@ void Application::main(const TC_Option &option) string config = TC_File::load2str(ServerConfig::ConfigFile); - __out__.debug() << "config:" << ServerConfig::ConfigFile << endl; - __out__.debug() << "config:" << config << endl; - main(config); } void Application::main(const string &config) { //增加一把全局静态锁, 避免一个进程内, 多个服务同时初始化时带来bug(一般测试中才会这样!) - static std::mutex mtx; - std::lock_guard lock(mtx); + static std::mutex gmtx; + std::lock_guard glock(gmtx); try { @@ -740,31 +797,22 @@ void Application::main(const string &config) //解析配置文件 parseConfig(config); + __out__.debug() << "config:" << ServerConfig::ConfigFile << endl; + __out__.debug() << "config:" << config << endl; + //初始化Proxy部分 initializeClient(); //初始化Server部分 initializeServer(); - vector adapters; - - //绑定对象和端口 - bindAdapter(adapters); - - stringstream os; + _serverBaseInfo = ServerConfig::toServerBaseInfo(); - //输出所有adapter - outAllAdapter(os); - - __out__.info() << os.str(); - - __out__.info() << "\n" << TC_Common::outfill("[initialize server] ", '.') << " [Done]" << endl; - - __out__.info() << OUT_LINE_LONG << endl; + initializeAdapter(); { bool initing = true; - std::mutex mtx; + std::mutex kmtx; std::condition_variable cond; std::thread keepActiving([&] @@ -772,10 +820,10 @@ void Application::main(const string &config) do { //发送心跳给node, 表示正在启动 - TARS_KEEPACTIVING; + _keepAliveNodeFHelper->keepActiving(); //等待initialize初始化完毕 - std::unique_lock lock(mtx); + std::unique_lock lock(kmtx); cond.wait_for(lock, std::chrono::seconds(5), [&](){ return !initing; }); @@ -790,7 +838,7 @@ void Application::main(const string &config) initialize(); { - std::unique_lock lock(mtx); + std::unique_lock lock(kmtx); initing = false; cond.notify_all(); } @@ -808,6 +856,25 @@ void Application::main(const string &config) } } + //绑定对象和端口 + bindAdapters(); + + if (!_applicationCommunicator->getProperty("locator").empty() && _serverBaseInfo.BakType > 0) + { + int timeout = TC_Common::strto(_conf.get("/tars/application/server", "5000")); + if (timeout < 5000) + { + timeout = 5000; + } + + _masterSlaveCheckThread = new std::thread(std::bind(&Application::checkMasterSlave, this, timeout)); + } + else + { + // 非主备模式时,默认响应 onMaster + onMaster(); + } + //动态加载配置文件 TARS_ADD_ADMIN_CMD_PREFIX(TARS_CMD_LOAD_CONFIG, Application::cmdLoadConfig); @@ -851,10 +918,12 @@ void Application::main(const string &config) TARS_ADD_ADMIN_CMD_PREFIX(TARS_CMD_RESOURCE, Application::cmdViewResource); //上报版本 - TARS_REPORTVERSION(TARS_VERSION); + _keepAliveNodeFHelper->reportVersion(TARS_VERSION); +// TARS_REPORTVERSION(TARS_VERSION); //发送心跳给node, 表示启动了 - TARS_KEEPALIVE(""); + _keepAliveNodeFHelper->keepAlive(); +// TARS_KEEPALIVE(""); //发送给notify表示服务启动了 RemoteNotify::getInstance()->report("restart"); @@ -908,6 +977,53 @@ void Application::main(const string &config) LocalRollLogger::getInstance()->sync(false); } +void Application::initializeAdapter() +{ + //创建adapter, 不绑定端口 + vector adapters = createAdapter(); + + if (!_serverBaseInfo.Local.empty()) + { + _servantHelper->addServant("AdminObj", this); + + string adminAdapter = "AdminAdapter"; + + _servantHelper->setAdapterServant(adminAdapter, "AdminObj"); + + TC_EpollServer::BindAdapterPtr lsPtr = _epollServer->createBindAdapter(adminAdapter, _serverBaseInfo.Local, 1, this); + + setAdapter(lsPtr, adminAdapter); + + lsPtr->setMaxConns(TC_EpollServer::BindAdapter::DEFAULT_MAX_CONN); + + lsPtr->setQueueCapacity(TC_EpollServer::BindAdapter::DEFAULT_QUEUE_CAP); + + lsPtr->setQueueTimeout(TC_EpollServer::BindAdapter::DEFAULT_QUEUE_TIMEOUT); + + lsPtr->setProtocolName("tars"); + + lsPtr->setProtocol(AppProtocol::parse); + + adapters.push_back(lsPtr); + + //admin端口先做绑定, 服务就算一直卡着initialize, 也能被外部管理了. + _epollServer->bind(lsPtr); + } + + _epollServer->setAdapter(adapters); + + stringstream os; + + //输出所有adapter + outAllAdapter(os); + + __out__.info() << os.str(); + + __out__.info() << "\n" << TC_Common::outfill("[initialize server] ", '.') << " [Done]" << endl; + + __out__.info() << OUT_LINE_LONG << endl; + +} void Application::parseConfig(const string &config) { @@ -947,7 +1063,17 @@ void Application::initializeClient() __out__.info() << "\n" << OUT_LINE_LONG << endl; //初始化通信器 - _communicator = CommunicatorFactory::getInstance()->getCommunicator(_conf); + if(!_communicator) + { + _communicator = CommunicatorFactory::getInstance()->getCommunicator(_conf); + _applicationCommunicator = _communicator; + } + else + { + //一个进程内嵌多个Application时发生, 正常业务服务不会发生 + _applicationCommunicator = CommunicatorFactory::getInstance()->getCommunicator(_conf, TC_Common::tostr(this)); + } + _applicationCommunicator->initialize(); __out__.info() << TC_Common::outfill("[proxy config]:") << endl; @@ -962,19 +1088,19 @@ void Application::outClient(ostream &os) { os << OUT_LINE << "\n" << TC_Common::outfill("[load client]:") << endl; - os << TC_Common::outfill("locator") << _communicator->getProperty("locator") << endl; - os << TC_Common::outfill("sync-invoke-timeout") << _communicator->getProperty("sync-invoke-timeout") << endl; - os << TC_Common::outfill("async-invoke-timeout") << _communicator->getProperty("async-invoke-timeout") << endl; - os << TC_Common::outfill("refresh-endpoint-interval") << _communicator->getProperty("refresh-endpoint-interval") << endl; - os << TC_Common::outfill("stat") << _communicator->getProperty("stat") << endl; - os << TC_Common::outfill("property") << _communicator->getProperty("property") << endl; - os << TC_Common::outfill("report-interval") << _communicator->getProperty("report-interval") << endl; - os << TC_Common::outfill("keep-alive-interval") << _communicator->getProperty("keep-alive-interval") << endl; - os << TC_Common::outfill("netthread") << _communicator->getProperty("netthread") << endl; - os << TC_Common::outfill("asyncthread") << _communicator->getProperty("asyncthread") << endl; - os << TC_Common::outfill("modulename") << _communicator->getProperty("modulename") << endl; - os << TC_Common::outfill("enableset") << _communicator->getProperty("enableset") << endl; - os << TC_Common::outfill("setdivision") << _communicator->getProperty("setdivision") << endl; + os << TC_Common::outfill("locator") << _applicationCommunicator->getProperty("locator") << endl; + os << TC_Common::outfill("sync-invoke-timeout") << _applicationCommunicator->getProperty("sync-invoke-timeout") << endl; + os << TC_Common::outfill("async-invoke-timeout") << _applicationCommunicator->getProperty("async-invoke-timeout") << endl; + os << TC_Common::outfill("refresh-endpoint-interval") << _applicationCommunicator->getProperty("refresh-endpoint-interval") << endl; + os << TC_Common::outfill("stat") << _applicationCommunicator->getProperty("stat") << endl; + os << TC_Common::outfill("property") << _applicationCommunicator->getProperty("property") << endl; + os << TC_Common::outfill("report-interval") << _applicationCommunicator->getProperty("report-interval") << endl; + os << TC_Common::outfill("keep-alive-interval") << _applicationCommunicator->getProperty("keep-alive-interval") << endl; + os << TC_Common::outfill("netthread") << _applicationCommunicator->getProperty("netthread") << endl; + os << TC_Common::outfill("asyncthread") << _applicationCommunicator->getProperty("asyncthread") << endl; + os << TC_Common::outfill("modulename") << _applicationCommunicator->getProperty("modulename") << endl; + os << TC_Common::outfill("enableset") << _applicationCommunicator->getProperty("enableset") << endl; + os << TC_Common::outfill("setdivision") << _applicationCommunicator->getProperty("setdivision") << endl; } string Application::toDefault(const string &s, const string &sDefault) @@ -998,7 +1124,7 @@ void Application::addServantProtocol(const string& servant, const TC_NetWorkBuff { string adapterName = _servantHelper->getServantAdapter(servant); - if (adapterName == "") + if (adapterName.empty()) { throw runtime_error("addServantProtocol fail, no found adapter for servant:" + servant); } @@ -1012,9 +1138,9 @@ void Application::addAcceptCallback(const TC_EpollServer::accept_callback_functo void Application::onAccept(TC_EpollServer::Connection* cPtr) { - for (size_t i = 0; i < _acceptFuncs.size(); ++i) + for (const auto & _acceptFunc : _acceptFuncs) { - _acceptFuncs[i](cPtr); + _acceptFunc(cPtr); } } @@ -1025,6 +1151,11 @@ TC_EpollServer::BindAdapterPtr Application::getBindAdapter(const string &obj) return _epollServer->getBindAdapter(adapter); } +bool Application::isTerminate() +{ + return !_epollServer || _epollServer->isTerminate(); +} + //void Application::addServantOnClose(const string& servant, const TC_EpollServer::close_functor& cf) //{ // string adapterName = _servantHelper->getServantAdapter(servant); @@ -1041,6 +1172,7 @@ void Application::outServer(ostream &os) { os << TC_Common::outfill("Application(app)") << ServerConfig::Application << endl; os << TC_Common::outfill("ServerName(server)") << ServerConfig::ServerName << endl; + os << TC_Common::outfill("NodeName(nodename)") << ServerConfig::NodeName << endl; os << TC_Common::outfill("BasePath(basepath)") << ServerConfig::BasePath << endl; os << TC_Common::outfill("DataPath(datapath)") << ServerConfig::DataPath << endl; os << TC_Common::outfill("LocalIp(localip)") << ServerConfig::LocalIp << endl; @@ -1059,10 +1191,11 @@ void Application::outServer(ostream &os) os << TC_Common::outfill("CloseCout(closecout)") << ServerConfig::CloseCout << endl; os << TC_Common::outfill("NetThread(netthread)") << ServerConfig::NetThread << endl; os << TC_Common::outfill("ManualListen(manuallisten)") << ServerConfig::ManualListen << endl; -// os << TC_Common::outfill("MergeNetImp(mergenetimp)") << ServerConfig::MergeNetImp << endl; os << TC_Common::outfill("ReportFlow(reportflow)") << ServerConfig::ReportFlow<< endl; os << TC_Common::outfill("BackPacketLimit(backpacketlimit)") << ServerConfig::BackPacketLimit<< endl; os << TC_Common::outfill("BackPacketMin(backpacketmin)") << ServerConfig::BackPacketMin<< endl; + os << TC_Common::outfill("BakType(baktype)") << ServerConfig::BakType << endl; + os << TC_Common::outfill("BakFlag(bakflag)") << ServerConfig::BakFlag << endl; #if TARS_SSL os << TC_Common::outfill("Ca(ca)") << ServerConfig::CA << endl; @@ -1082,7 +1215,7 @@ void Application::initializeServer() ServerConfig::Application = toDefault(_conf.get("/tars/application/server"), "UNKNOWN"); //缺省采用进程名称 - string exe = ""; + string exe; try { @@ -1096,7 +1229,6 @@ void Application::initializeServer() ServerConfig::ServerName = toDefault(_conf.get("/tars/application/server"), exe); - #if TARGET_PLATFORM_WINDOWS ServerConfig::BasePath = TC_File::simplifyDirectory(_conf.get("/tars/application/server")) + FILE_SEP; if (ServerConfig::BasePath == FILE_SEP) @@ -1122,10 +1254,13 @@ void Application::initializeServer() #endif ServerConfig::TarsPath = TC_File::simplifyDirectory(ServerConfig::LogPath + FILE_SEP + ".." + FILE_SEP) + FILE_SEP; + ServerConfig::BakFlag = TC_Common::strto(_conf.get("/tars/application/server", "0")); + ServerConfig::BakType = TC_Common::strto(_conf.get("/tars/application/server", "0")); ServerConfig::LogSize = TC_Common::toSize(toDefault(_conf.get("/tars/application/server"), "52428800"), 52428800); ServerConfig::LogNum = TC_Common::strto(toDefault(_conf.get("/tars/application/server"), "10")); ServerConfig::LocalIp = _conf.get("/tars/application/server"); + ServerConfig::NodeName = toDefault(_conf.get("/tars/application/server"), ServerConfig::LocalIp); ServerConfig::Local = _conf.get("/tars/application/server"); ServerConfig::Node = _conf.get("/tars/application/server"); ServerConfig::Log = _conf.get("/tars/application/server"); @@ -1137,13 +1272,11 @@ void Application::initializeServer() ServerConfig::CoroutineMemSize = TC_Common::toSize(toDefault(_conf.get("/tars/application/server"), "1G"), 1024*1024*1024); ServerConfig::CoroutineStackSize= (uint32_t)TC_Common::toSize(toDefault(_conf.get("/tars/application/server"), "128K"), 1024*128); ServerConfig::ManualListen = _conf.get("/tars/application/server", "0") == "0" ? false : true; -// ServerConfig::MergeNetImp = _conf.get("/tars/application/server", "0") == "0" ? false : true; ServerConfig::NetThread = TC_Common::strto(toDefault(_conf.get("/tars/application/server"), "1")); ServerConfig::CloseCout = _conf.get("/tars/application/server","1")=="0"?0:1; ServerConfig::BackPacketLimit = TC_Common::strto(_conf.get("/tars/application/server", TC_Common::tostr(100*1024*1024))); ServerConfig::BackPacketMin = TC_Common::strto(_conf.get("/tars/application/server", "1024")); - ServerConfig::Context["node_name"] = ServerConfig::LocalIp; #if TARS_SSL ServerConfig::CA = _conf.get("/tars/application/server"); ServerConfig::Cert = _conf.get("/tars/application/server"); @@ -1161,24 +1294,22 @@ void Application::initializeServer() } #endif - if (ServerConfig::LocalIp.empty()) { // ServerConfig::LocalIp = "127.0.0.1"; - vector v = TC_Socket::getLocalHosts(); + vector v = TC_Socket::getLocalHosts(AF_INET, false); ServerConfig::LocalIp = "127.0.0.1"; - //获取第一个非127.0.0.1的IP - for(size_t i = 0; i < v.size(); i++) + if(!v.empty()) { - if(v[i] != "127.0.0.1") - { - ServerConfig::LocalIp = v[i]; - break; - } + ServerConfig::LocalIp = v[0]; } } + //设置节点名称, 请求tarsregistry会在context中带过去, 方便知道从哪来的请求 + _applicationCommunicator->_clientConfig.NodeName = ServerConfig::NodeName; + _applicationCommunicator->_clientConfig.Context["node_name"] = ServerConfig::NodeName; + onServerConfig(); ostringstream os; @@ -1214,9 +1345,6 @@ void Application::initializeServer() _epollServer->setOnAccept(std::bind(&Application::onAccept, this, std::placeholders::_1)); //初始化服务是否对空链接进行超时检查 -// bool bEnable = (_conf.get("/tars/application/server","0")=="1")?true:false; - -// _epollServer->enAntiEmptyConnAttack(bEnable); _epollServer->setEmptyConnTimeout(TC_Common::strto(toDefault(_conf.get("/tars/application/server"), "0"))); @@ -1228,7 +1356,7 @@ void Application::initializeServer() /////////////////////////////////////////////////////////////////////////////////////////////////// //初始化本地Log __out__.info() << OUT_LINE << "\n" << TC_Common::outfill("[set roll logger] ") << "OK" << endl; - LocalRollLogger::getInstance()->setLogInfo(ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, ServerConfig::LogSize, ServerConfig::LogNum, _communicator, ServerConfig::Log); + LocalRollLogger::getInstance()->setLogInfo(ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, ServerConfig::LogSize, ServerConfig::LogNum, _applicationCommunicator, ServerConfig::Log); _epollServer->setLocalLogger(LocalRollLogger::getInstance()->logger()); //初始化是日志为同步 @@ -1249,63 +1377,35 @@ void Application::initializeServer() //初始化到LogServer代理 __out__.info() << OUT_LINE << "\n" << TC_Common::outfill("[set time logger] ") << "OK" << endl; bool bLogStatReport = (_conf.get("/tars/application/server", "0") == "1") ? true : false; - RemoteTimeLogger::getInstance()->setLogInfo(_communicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, setDivision(), bLogStatReport); + RemoteTimeLogger::getInstance()->setLogInfo(_applicationCommunicator, ServerConfig::Log, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::LogPath, setDivision(), bLogStatReport); /////////////////////////////////////////////////////////////////////////////////////////////////// //初始化到配置中心代理 __out__.info() << OUT_LINE << "\n" << TC_Common::outfill("[set remote config] ") << "OK" << endl; - RemoteConfig::getInstance()->setConfigInfo(_communicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath,setDivision()); + _remoteConfig = std::make_shared(); + _remoteConfig->setConfigInfo(_applicationCommunicator, ServerConfig::Config, ServerConfig::Application, ServerConfig::ServerName, ServerConfig::BasePath, setDivision(), 5); /////////////////////////////////////////////////////////////////////////////////////////////////// //初始化到信息中心代理 __out__.info() << OUT_LINE << "\n" << TC_Common::outfill("[set remote notify] ") << "OK" << endl; - RemoteNotify::getInstance()->setNotifyInfo(_communicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision(), ServerConfig::LocalIp); + RemoteNotify::getInstance()->setNotifyInfo(_applicationCommunicator, ServerConfig::Notify, ServerConfig::Application, ServerConfig::ServerName, setDivision()); /////////////////////////////////////////////////////////////////////////////////////////////////// //初始化到Node的代理 __out__.info() << OUT_LINE << "\n" << TC_Common::outfill("[set node proxy]") << "OK" << endl; - KeepAliveNodeFHelper::getInstance()->setNodeInfo(_communicator, ServerConfig::Node, ServerConfig::Application, ServerConfig::ServerName); + _keepAliveNodeFHelper = std::make_shared(); + _keepAliveNodeFHelper->setNodeInfo(_applicationCommunicator, ServerConfig::Node, ServerConfig::Application, ServerConfig::ServerName); /////////////////////////////////////////////////////////////////////////////////////////////////// //初始化管理对象 __out__.info() << OUT_LINE << "\n" << TC_Common::outfill("[set admin adapter]") << "OK" << endl; - if (!ServerConfig::Local.empty()) - { - _servantHelper->addServant("AdminObj", this); - - string adminAdapter = "AdminAdapter"; - - _servantHelper->setAdapterServant(adminAdapter, "AdminObj"); - - TC_EpollServer::BindAdapterPtr lsPtr = _epollServer->createBindAdapter(adminAdapter, ServerConfig::Local, 1, this); - - setAdapter(lsPtr, adminAdapter); - - lsPtr->setMaxConns(TC_EpollServer::BindAdapter::DEFAULT_MAX_CONN); - - lsPtr->setQueueCapacity(TC_EpollServer::BindAdapter::DEFAULT_QUEUE_CAP); - - lsPtr->setQueueTimeout(TC_EpollServer::BindAdapter::DEFAULT_QUEUE_TIMEOUT); - - lsPtr->setProtocolName("tars"); - - lsPtr->setProtocol(AppProtocol::parse); - - _epollServer->bind(lsPtr); - - } - //队列取平均值 - if(!_communicator->getProperty("property").empty()) + if(!_applicationCommunicator->getProperty("property").empty()) { - string sRspQueue(""); - sRspQueue += ServerConfig::Application; - sRspQueue += "."; - sRspQueue += ServerConfig::ServerName; - sRspQueue += ".sendrspqueue"; + string sRspQueue= "sendrspqueue"; - g_pReportRspQueue = _communicator->getStatReport()->createPropertyReport(sRspQueue, PropertyReport::avg()); + g_pReportRspQueue = _applicationCommunicator->getStatReport()->createPropertyReport(sRspQueue, PropertyReport::avg()); } TarsTimeLogger::getInstance()->enableLocal(TRACE_LOG_FILENAME, false); @@ -1351,9 +1451,11 @@ void Application::setAdapter(TC_EpollServer::BindAdapterPtr& adapter, const stri } -void Application::bindAdapter(vector& adapters) +vector Application::createAdapter() { - string sPrefix = ServerConfig::Application + "." + ServerConfig::ServerName + "."; + vector adapters; + + string sPrefix = _serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + "."; vector adapterName; @@ -1374,13 +1476,13 @@ void Application::bindAdapter(vector& adapters) ep.parse(_conf[sLastPath + ""]); if (ep.getHost() == "localip") { - ep.setHost(ServerConfig::LocalIp); + ep.setHost(_serverBaseInfo.LocalIp); } TC_EpollServer::BindAdapterPtr bindAdapter = _epollServer->createBindAdapter(adapterName[i], _conf[sLastPath + ""], TC_Common::strto(_conf.get(sLastPath + "", "1")), this); //init auth & ssl - setAdapter(bindAdapter, adapterName[i]); + setAdapter(bindAdapter, adapterName[i]); bindAdapter->setMaxConns(TC_Common::strto(_conf.get(sLastPath + "", "128"))); @@ -1396,11 +1498,11 @@ void Application::bindAdapter(vector& adapters) bindAdapter->setProtocolName(_conf.get(sLastPath + "", "tars")); - bindAdapter->setBackPacketBuffLimit(ServerConfig::BackPacketLimit); + bindAdapter->setBackPacketBuffLimit(ServerConfig::BackPacketLimit); - bindAdapter->setBackPacketBuffMin(ServerConfig::BackPacketMin); + bindAdapter->setBackPacketBuffMin(ServerConfig::BackPacketMin); - if (bindAdapter->isTarsProtocol()) + if (bindAdapter->isTarsProtocol()) { bindAdapter->setProtocol(AppProtocol::parse); } @@ -1414,36 +1516,51 @@ void Application::bindAdapter(vector& adapters) } #endif - if(ServerConfig::ManualListen) { + if(_serverBaseInfo.ManualListen) + { //手工监听 bindAdapter->enableManualListen(); } - _epollServer->bind(bindAdapter); - - adapters.push_back(bindAdapter); - //队列取平均值 - if(!_communicator->getProperty("property").empty()) + if(!_applicationCommunicator->getProperty("property").empty()) { PropertyReportPtr p; - p = _communicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".queue", PropertyReport::avg()); + p = _applicationCommunicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".queue", PropertyReport::avg()); bindAdapter->_pReportQueue = p.get(); - p = _communicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".connectRate", PropertyReport::avg()); + p = _applicationCommunicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".connectRate", PropertyReport::avg()); bindAdapter->_pReportConRate = p.get(); - p = _communicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".timeoutNum", PropertyReport::sum()); + p = _applicationCommunicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".timeoutNum", PropertyReport::sum()); bindAdapter->_pReportTimeoutNum = p.get(); - p = _communicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".queueWaitTime", - PropertyReport::avg(), PropertyReport::min(), PropertyReport::max(), PropertyReport::count()); + p = _applicationCommunicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".queueWaitTime", + PropertyReport::avg(), PropertyReport::min(), PropertyReport::max(), PropertyReport::count(), + PropertyReport::distr({5, 10, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000})); bindAdapter->_pReportQueueWaitTime = p.get(); - p = _communicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".servantHandleTime", - PropertyReport::avg(), PropertyReport::min(), PropertyReport::max(), PropertyReport::count()); + p = _applicationCommunicator->getStatReport()->createPropertyReport(bindAdapter->getName() + ".servantHandleTime", + PropertyReport::avg(), PropertyReport::min(), PropertyReport::max(), PropertyReport::count(), + PropertyReport::distr({5, 10, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000, 100000})); bindAdapter->_pReportServantHandleTime = p.get(); } + + adapters.push_back(bindAdapter); + } + } + + return adapters; +} + +void Application::bindAdapters() +{ + for(auto adapter : _epollServer->getBindAdapters()) + { + if(!adapter->getSocket().isValid()) + { + //未绑定, 才绑定 + _epollServer->bind(adapter); } } } @@ -1475,10 +1592,88 @@ void Application::outAdapter(ostream &os, const string &v, TC_EpollServer::BindA os << TC_Common::outfill("order") << (lsPtr->getOrder() == TC_EpollServer::BindAdapter::ALLOW_DENY ? "allow,deny" : "deny,allow") << endl; os << TC_Common::outfill("allow") << TC_Common::tostr(lsPtr->getAllow()) << endl; os << TC_Common::outfill("deny") << TC_Common::tostr(lsPtr->getDeny()) << endl; - // os << outfill("queuesize") << lsPtr->getRecvBufferSize() << endl; os << TC_Common::outfill("connections") << lsPtr->getNowConnection() << endl; os << TC_Common::outfill("protocol") << lsPtr->getProtocolName() << endl; os << TC_Common::outfill("handlethread") << lsPtr->getHandleNum() << endl; } -////////////////////////////////////////////////////////////////////////////////////////////////// + +void Application::checkMasterSlave(int timeout) +{ + int exceptionTimes = 0; + + GetMasterSlaveLock req; + req.application = _serverBaseInfo.Application; + req.server_name = _serverBaseInfo.ServerName; + req.node_name = _serverBaseInfo.NodeName; + req.bakType = _serverBaseInfo.BakType; + req.isMaster = false; + req.lastErr = false; + req.timeout = timeout; + + bool firstCheck = true; + + QueryFPrx queryFPrx = _applicationCommunicator->stringToProxy(_applicationCommunicator->getProperty("locator")); + + do + { + try + { + int ret = queryFPrx->getLocker(req); + + if (0 == ret) + { + //抢到主了, 如果不是主, 则变成主, 且回调 + req.lastErr = false; + if (!req.isMaster) + { + req.isMaster = true; + TLOG_INFO("This service node has become the master node!" << endl); + TARS_NOTIFY_ERROR("Auto change to be master, This service node become the master!"); + onMaster(); + } + firstCheck = false; + } else if (1 == ret) + { + //没抢到主, 如果不是备, 则变成备, 且回调 + req.lastErr = false; + if (req.isMaster || firstCheck) + { + req.isMaster = false; + TLOG_ERROR("The service node has become the slave node." << endl); + TARS_NOTIFY_ERROR("Auto change to be slave, This service node become the slave!"); + onSlave(); + } + firstCheck = false; + } else + { + TLOG_ERROR("getLocker return exception, ret:" << ret << endl); + req.lastErr = true; + } + + exceptionTimes = 0; + } + catch (exception &ex) + { + ++exceptionTimes; + TLOG_ERROR("getLocker call exception:" << ex.what() << endl); +// if (req.isMaster) +// { +// if (exceptionTimes > 3) +// { +// //持续3次都无法访问主控, 则认为自己异常了!! +// req.isMaster = false; +// TLOG_ERROR("The service node has become the slave node because call getLocker exception." << endl); +// TARS_NOTIFY_ERROR( +// "Auto change to be slave, This service node has become the slave node because call getLocker exception!"); +// onSlave(); +// } +// } + } + + TC_ThreadLock::Lock lock(_masterSlaveLock); + _masterSlaveLock.timedWait(timeout/3); + } + while(!_terminateCheckMasterSlave); +} + } diff --git a/servant/libservant/Communicator.cpp b/servant/libservant/Communicator.cpp index 822c5079..9ab47751 100644 --- a/servant/libservant/Communicator.cpp +++ b/servant/libservant/Communicator.cpp @@ -27,17 +27,7 @@ namespace tars ////////////////////////////////////////////////////////////////////////////////////////////// -string ClientConfig::LocalIp = "127.0.0.1"; -string ClientConfig::ModuleName = "unknown"; - -set ClientConfig::SetLocalIp; - -bool ClientConfig::SetOpen = false; - -string ClientConfig::SetDivision = ""; - -string ClientConfig::TarsVersion = string(TARS_VERSION); ////////////////////////////////////////////////////////////////////////////////////////////// @@ -250,15 +240,15 @@ void Communicator::initialize() }); - ClientConfig::TarsVersion = TARS_VERSION; + _clientConfig.TarsVersion = TARS_VERSION; - ClientConfig::SetOpen = TC_Common::lower(getProperty("enableset", "n")) == "y" ? true : false; + _clientConfig.SetOpen = TC_Common::lower(getProperty("enableset", "n")) == "y" ? true : false; - if (ClientConfig::SetOpen) + if (_clientConfig.SetOpen) { - ClientConfig::SetDivision = getProperty("setdivision"); + _clientConfig.SetDivision = getProperty("setdivision"); - vector vtSetDivisions = TC_Common::sepstr(ClientConfig::SetDivision, "."); + vector vtSetDivisions = TC_Common::sepstr(_clientConfig.SetDivision, "."); string sWildCard = "*"; @@ -267,24 +257,24 @@ void Communicator::initialize() || vtSetDivisions[1] == sWildCard) { //set分组名不对时默认没有打开set分组 - ClientConfig::SetOpen = false; + _clientConfig.SetOpen = false; setProperty("enableset", "n"); - TLOGERROR("[set division name error:" << ClientConfig::SetDivision << ", client failed to open set]" << endl); + TLOGERROR("[set division name error:" << _clientConfig.SetDivision << ", client failed to open set]" << endl); } } - ClientConfig::LocalIp = getProperty("localip", ""); + _clientConfig.LocalIp = getProperty("localip", ""); - if (ClientConfig::SetLocalIp.empty()) + if (_clientConfig.SetLocalIp.empty()) { - vector v = TC_Socket::getLocalHosts(); + vector v = TC_Socket::getLocalHosts(AF_INET, false); + if (_clientConfig.LocalIp.empty() && !v.empty()) + { + _clientConfig.LocalIp = v[0]; + } for (size_t i = 0; i < v.size(); i++) { - if (v[i] != "127.0.0.1" && ClientConfig::LocalIp.empty()) - { - ClientConfig::LocalIp = v[i]; - } - ClientConfig::SetLocalIp.insert(v[i]); + _clientConfig.SetLocalIp.insert(v[i]); } } @@ -295,13 +285,13 @@ void Communicator::initialize() { exe = TC_File::extractFileName(TC_File::getExePath()); } - catch (TC_File_Exception& ex) + catch (exception& ex) { //取失败则使用ip代替进程名 - exe = ClientConfig::LocalIp; + exe = _clientConfig.LocalIp; } - ClientConfig::ModuleName = getProperty("modulename", exe); + _clientConfig.ModuleName = getProperty("modulename", exe); #if TARS_SSL @@ -348,6 +338,8 @@ void Communicator::initialize() _asyncThreadNum = MAX_CLIENT_ASYNCTHREAD_NUM; } + _schedCommunicatorEpoll.resize(MAX_CLIENT_NOTIFYEVENT_NUM); + bool merge = TC_Common::strto(getProperty("mergenetasync", "0")); //异步队列的大小 @@ -381,12 +373,12 @@ void Communicator::initialize() } { - std::unique_lock lock(_mutex); - _cond.wait(lock, [&]{ return _communicatorEpollStartNum == clientThreadNum; }); + std::unique_lock tlock(_mutex); + _cond.wait(tlock, [&]{ return _communicatorEpollStartNum == clientThreadNum; }); } //异步队列数目上报 - _reportAsyncQueue= getStatReport()->createPropertyReport(ClientConfig::ModuleName + ".asyncqueue", PropertyReport::avg()); + _reportAsyncQueue= getStatReport()->createPropertyReport("asyncqueue", PropertyReport::avg()); //初始化统计上报接口 string statObj = getProperty("stat", ""); @@ -420,8 +412,15 @@ void Communicator::initialize() propertyPrx->tars_open_keepalive(false); } - string sSetDivision = ClientConfig::SetOpen ? ClientConfig::SetDivision : ""; - _statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, 0, 0, iMaxReportSize, iReportTimeout); + string locator = getProperty("locator", ""); + if(!locator.empty()) + { + _queryFPrx = stringToProxy(locator); + _queryFPrx->tars_open_keepalive(false); + } + + string sSetDivision = _clientConfig.SetOpen ? _clientConfig.SetDivision : ""; + _statReport->setReportInfo(statPrx, propertyPrx, _clientConfig.ModuleName, _clientConfig.LocalIp, sSetDivision, iReportInterval, iMaxReportSize, iReportTimeout); #if TARS_OPENTRACKING string collector_host = getProperty("collector_host", ""); @@ -486,43 +485,59 @@ vector> Communicator::getAllCommunicatorEpoll() return communicatorEpolls; } -void Communicator::forEachSchedCommunicatorEpoll(std::function &)> func) +void Communicator::forEachSchedCommunicatorEpoll(const std::function &)>& func) { - TC_LockT lock(_schedMutex); - for(auto it : _schedCommunicatorEpoll) +// TC_LockT lock(_schedMutex); +// for(const auto& it : _schedCommunicatorEpoll) +// { +// func(it.second); +// } + + for(const auto& it : _schedCommunicatorEpoll) { - func(it.second); + if(it) + { + func(it); + } } } shared_ptr Communicator::createSchedCommunicatorEpoll(size_t netThreadSeq, const shared_ptr &reqInfoQueue) { + assert(netThreadSeq < MAX_CLIENT_NOTIFYEVENT_NUM); + shared_ptr communicatorEpoll = std::make_shared(this, netThreadSeq); communicatorEpoll->initializeEpoller(); communicatorEpoll->initNotify(netThreadSeq, reqInfoQueue); - { - TC_LockT lock(_schedMutex); + _schedCommunicatorEpoll[netThreadSeq] = communicatorEpoll; - _schedCommunicatorEpoll.insert(std::make_pair(netThreadSeq, communicatorEpoll)); - } +// { +// TC_LockT lock(_schedMutex); +// +// _schedCommunicatorEpoll.insert(std::make_pair(netThreadSeq, communicatorEpoll)); +// } return communicatorEpoll; } void Communicator::eraseSchedCommunicatorEpoll(size_t netThreadSeq) { - shared_ptr ce; - { - TC_LockT lock(_schedMutex); + assert(netThreadSeq < MAX_CLIENT_NOTIFYEVENT_NUM); - ce = _schedCommunicatorEpoll[netThreadSeq]; - - _schedCommunicatorEpoll.erase(netThreadSeq); - } + shared_ptr ce = _schedCommunicatorEpoll[netThreadSeq]; + _schedCommunicatorEpoll[netThreadSeq].reset(); +// { +// TC_LockT lock(_schedMutex); +// +// ce = _schedCommunicatorEpoll[netThreadSeq]; +// +// _schedCommunicatorEpoll.erase(netThreadSeq); +// } +// if(ce) { ce->terminate(); @@ -534,13 +549,10 @@ void Communicator::reloadLocator() for (size_t i = 0; i < _communicatorEpoll.size(); ++i) { _communicatorEpoll[i]->_epoller->syncCallback(std::bind(&CommunicatorEpoll::loadObjectLocator, _communicatorEpoll[i].get())); - -// _communicatorEpoll[i]->loadObjectLocator(); } forEachSchedCommunicatorEpoll([](const shared_ptr &c){ c->_epoller->syncCallback(std::bind(&CommunicatorEpoll::loadObjectLocator, c.get())); -// c->loadObjectLocator(); }); } @@ -576,8 +588,8 @@ int Communicator::reloadProperty(string & sResult) propertyPrx = stringToProxy(propertyObj); } - string sSetDivision = ClientConfig::SetOpen ? ClientConfig::SetDivision : ""; - _statReport->setReportInfo(statPrx, propertyPrx, ClientConfig::ModuleName, ClientConfig::LocalIp, sSetDivision, iReportInterval, 0, 0, iMaxReportSize, iReportTimeout); + string sSetDivision = _clientConfig.SetOpen ? _clientConfig.SetDivision : ""; + _statReport->setReportInfo(statPrx, propertyPrx, _clientConfig.ModuleName, _clientConfig.LocalIp, sSetDivision, iReportInterval, iMaxReportSize, iReportTimeout); sResult = "locator=" + getProperty("locator", "") + "\r\n" + "stat=" + statObj + "\r\n" + "property=" + propertyObj + "\r\n" + @@ -754,6 +766,12 @@ ServantProxy* Communicator::getServantProxy(const string& objectName, const stri return _servantProxyFactory->getServantProxy(objectName, setName, rootServant); } +ServantProxy * Communicator::setServantProxy(ServantProxy * proxy,const string& objectName,const string& setName, bool rootServant) +{ + Communicator::initialize(); + proxy->setComm(this , objectName,setName); + return _servantProxyFactory->setServantProxy(proxy,objectName, setName, rootServant); +} StatReport* Communicator::getStatReport() { Communicator::initialize(); diff --git a/servant/libservant/Current.cpp b/servant/libservant/Current.cpp index 7ca9f15d..ca785087 100644 --- a/servant/libservant/Current.cpp +++ b/servant/libservant/Current.cpp @@ -24,11 +24,11 @@ namespace tars { ////////////////////////////////////////////////////////////////// -Current::Current(ServantHandle *pServantHandle) +Current::Current(const shared_ptr & pServantHandle) : _servantHandle(pServantHandle) , _response(true) , _ret(0) - , _reportStat(true) +// , _reportStat(true) , _traceCall(false) { @@ -36,27 +36,34 @@ Current::Current(ServantHandle *pServantHandle) Current::~Current() { - //TUP调用或单向调用,从服务端上报调用信息 - if(_reportStat) - { - if(_request.iVersion == TUPVERSION ) - { - reportToStat("tup_client"); - } - else if(_request.cPacketType == TARSONEWAY) - { - reportToStat("one_way_client"); - } - else if(_request.cPacketType == TARSNORMAL) - { - reportToStat("stat_from_server"); - } - else if (!_isTars && ServerConfig::ReportFlow) - { - //非tars客户端 从服务端上报调用信息 - reportToStat("not_tars_client"); - } - } +// //TUP调用或单向调用,从服务端上报调用信息 +// if(_reportStat && _servantHandle->getApplication()->getServerBaseInfo().ReportFlow && _servantHandle && _servantHandle->getApplication() && !_servantHandle->getApplication()->isTerminate() && !_servantHandle->getApplication()->getApplicationCommunicator()->isTerminating()) +// { +// StatReport *stat = _servantHandle->getApplication()->getApplicationCommunicator()->getStatReport(); +// +// if (stat && stat->getStatPrx()) +// { +// auto func = [&](const char *obj) +// { +// stat->report(obj, "", _request.sFuncName, _data->ip(), 0, (StatReport::StatResult) _ret, +// TNOWMS - _data->recvTimeStamp(), 0, false); +// }; +// +// if (_request.iVersion == TUPVERSION) +// { +// func("tup_client"); +// } else if (_request.cPacketType == TARSONEWAY) +// { +// func("one_way_client"); +// } else if (_request.cPacketType == TARSNORMAL) +// { +// func("stat_from_server"); +// } else if (!_isTars) +// { +// func("not_tars_client"); +// } +// } +// } } const string &Current::getHostName() const @@ -134,11 +141,16 @@ struct timeval Current::getRecvTime() const return tm; } -void Current::setReportStat(bool bReport) +int64_t Current::recvTimeStampUs() const { - _reportStat = bReport; + return _data->recvTimeStampUs(); } +//void Current::setReportStat(bool bReport) +//{ +// _reportStat = bReport; +//} +// const vector& Current::getRequestBuffer() const { if (_isTars) @@ -172,10 +184,6 @@ void Current::initialize(const shared_ptr &data) _data = data; -// Application *application = (Application*)this->_servantHandle->getApplication(); - -// _request.sServantName = application->getServantHelper()->getAdapterServant(_data->adapter()->getName()); - _isTars = _data->adapter()->isTarsProtocol(); if (_isTars) @@ -192,11 +200,7 @@ void Current::initializeClose(const shared_ptr &dat { _data = data; -// Application *application = (Application*)this->_servantHandle->getApplication(); - _request.sServantName = this->_servantHandle->getServant()->getName(); - -// _request.sServantName = application->getServantHelper()->getAdapterServant(_data->adapter()->getName()); } void Current::initialize(const vector& sRecvBuffer) @@ -211,7 +215,6 @@ void Current::initialize(const vector& sRecvBuffer) void Current::sendResponse(const char *buff, uint32_t len) { shared_ptr send = _data->createSendContext(); - // send->buffer()->assign(buff, len); send->buffer()->addBuffer(buff, len); _servantHandle->sendResponse(send); } @@ -226,7 +229,7 @@ void Current::sendResponse(int iRet, const vector &buff) ResponsePacket response; response.sBuffer = buff; - sendResponse(iRet, response, TARS_STATUS(), ""); + sendResponse(iRet, response, {}, ""); } void Current::sendResponse(int iRet, const string &buff) @@ -239,27 +242,27 @@ void Current::sendResponse(int iRet, const string &buff) ResponsePacket response; response.sBuffer.assign(buff.begin(), buff.end()); - sendResponse(iRet, response, TARS_STATUS(), ""); + sendResponse(iRet, response, {}, ""); } void Current::sendResponse(int iRet) { ResponsePacket response; - sendResponse(iRet, response, TARS_STATUS(), ""); + sendResponse(iRet, response, {}, ""); } void Current::sendResponse(int iRet, tars::TarsOutputStream& os) { ResponsePacket response; os.swap(response.sBuffer); - sendResponse(iRet, response, TARS_STATUS(), ""); + sendResponse(iRet, response, {}, ""); } void Current::sendResponse(int iRet, tup::UniAttribute& attr) { ResponsePacket response; attr.encode(response.sBuffer); - sendResponse(iRet, response, TARS_STATUS(), ""); + sendResponse(iRet, response, {}, ""); } void Current::sendResponse(int iRet, ResponsePacket &response, const map& status, const string & sResultDesc) @@ -287,7 +290,7 @@ void Current::sendResponse(int iRet, ResponsePacket &response, const mapsetBuffer(ProxyProtocol::toBuffer(os)); + { + StatReport *stat = _servantHandle->getApplication()->getApplicationCommunicator()->getStatReport(); + + if (stat && stat->getStatPrx()) + { + stat->report("stat_from_server", "", getFuncName(), getIp(), 0, (StatReport::StatResult) _ret, + TNOWMS - recvTimeStampUs() / 1000, 0, false); + } + } + _servantHandle->sendResponse(send); } + +void Current::sendPushResponse(int iRet, const string &funcName , vector &buff ) +{ + ResponsePacket response; + buff.swap(response.sBuffer); + + _ret = iRet; + + shared_ptr send = _data->createSendContext(); + + Int32 iHeaderLen = 0; + + // JceOutputStream os; +// JceOutputStream os; + TarsOutputStream os; + + //先预留4个字节长度 + os.writeBuf((const char *)&iHeaderLen, sizeof(iHeaderLen)); + + response.iRequestId = 0; + response.cPacketType = TARSNORMAL; + response.iMessageType = 0; + response.iVersion = TARSVERSION; + response.context = _responseContext; +// response.sServantName = _request.sServantName; +// response.sFuncName = funcName; + response.iRet = iRet; + response.sResultDesc = ""; + + TLOGTARS("[TAF]Current::sendPushResponse :"<< response.iMessageType << "|"<< response.iRequestId << endl); + + response.writeTo(os); + + assert(os.getLength() >= 4); + + iHeaderLen = htonl((int)(os.getLength())); + + memcpy((void*)os.getBuffer(), (const char *)&iHeaderLen, sizeof(iHeaderLen)); + + send->setBuffer(ProxyProtocol::toBuffer(os)); + + _servantHandle->sendResponse(send); +} + + void Current::sendPushResponse(int iRet, const string &funcName, TarsOutputStream& oss, const map &context) { ResponsePacket response; @@ -400,7 +458,7 @@ void Current::sendPushResponse(int iRet, const string &funcName, TarsOutputStrea void Current::close() { - if (_servantHandle) + if (_servantHandle && !_servantHandle->getApplication()->isTerminate()) { _servantHandle->close(_data); } @@ -408,23 +466,31 @@ void Current::close() ServantHandle* Current::getServantHandle() { - return _servantHandle; + return _servantHandle.get(); } -TC_EpollServer::BindAdapter* Current::getBindAdapter() +string Current::getModuleName() { - return _data->adapter().get(); + return _servantHandle->getModuleName(); } -void Current::reportToStat(const string& sObj) +TC_EpollServer::BindAdapter* Current::getBindAdapter() { - StatReport* stat = Application::getCommunicator()->getStatReport(); - - if(stat && stat->getStatPrx()) - { - stat->report(sObj, "", _request.sFuncName, _data->ip(), 0, (StatReport::StatResult)_ret, TNOWMS - _data->recvTimeStamp(), 0, false); - } + return _data->adapter().get(); } +// +//void Current::reportToStat(const string& sObj) +//{ +// if(_data->adapter() ) +// { +// StatReport *stat = comm->getStatReport(); +// +// if (stat && stat->getStatPrx()) +// { +// stat->report(sObj, "", _request.sFuncName, _data->ip(), 0, (StatReport::StatResult) _ret, TNOWMS - _data->recvTimeStamp(), 0, false); +// } +// } +//} void Current::setTrace(bool traceCall, const string& traceKey) { @@ -437,7 +503,7 @@ bool Current::isTraced() const return _traceCall; } -string Current::getTraceKey() const +const string &Current::getTraceKey() const { return _traceKey; } diff --git a/servant/libservant/EndpointInfo.cpp b/servant/libservant/EndpointInfo.cpp index 463bf589..01f74962 100755 --- a/servant/libservant/EndpointInfo.cpp +++ b/servant/libservant/EndpointInfo.cpp @@ -40,23 +40,12 @@ EndpointInfo::EndpointInfo(const TC_Endpoint &ep, const string &setDivision) EndpointInfo::EndpointInfo(const EndpointF &ep) : _setDivision(ep.setId) { - _ep.setHost(ep.host); - _ep.setPort(ep.port); - _ep.setTimeout(ep.timeout); - _ep.setType((TC_Endpoint::EType)ep.istcp); - _ep.setGrid(ep.grid); - _ep.setQos(ep.qos); - _ep.setWeight(ep.weight); - _ep.setWeightType(ep.weightType); - - _ep.setAuthType((TC_Endpoint::AUTH_TYPE)ep.authType); + _ep = toEndpointF(ep); _cmpDesc = createCompareDesc(); _desc = createDesc(); - } - string EndpointInfo::createCompareDesc() { stringstream ss; @@ -65,5 +54,170 @@ string EndpointInfo::createCompareDesc() return ss.str(); } +TC_Endpoint EndpointInfo::toEndpointF(const EndpointF &ep) +{ + TC_Endpoint tEp; + tEp.setHost(ep.host); + tEp.setPort(ep.port); + tEp.setTimeout(ep.timeout); + tEp.setType((TC_Endpoint::EType)ep.istcp); + tEp.setGrid(ep.grid); + tEp.setQos(ep.qos); + tEp.setWeight(ep.weight); + tEp.setWeightType(ep.weightType); + + tEp.setAuthType((TC_Endpoint::AUTH_TYPE)ep.authType); + + return tEp; +} + +EndpointF EndpointInfo::toEndpointF(const TC_Endpoint &tep, const string &nodeName) +{ + EndpointF ep; + ep.host = tep.getHost(); + ep.port = tep.getPort(); + ep.istcp = tep.getType(); + ep.nodeName = nodeName; + if(ep.nodeName.empty()) + { + ep.nodeName = tep.getHost(); + } + ep.timeout = tep.getTimeout(); + ep.authType = tep.getAuthType(); + ep.qos = tep.getQos(); + ep.weight = tep.getWeight(); + ep.weightType = tep.getWeightType(); + + return ep; +} + +vector EndpointInfo::toEndpointFs(const TC_Endpoint &ep, const string &nodeName) +{ + //如果ep的host是0.0.0.0, 则使用本地ip地址 + string host = ep.getHost(); + if (host == "0.0.0.0") + { + vector v; + vector ips = TC_Socket::getLocalHosts(AF_INET, false); + + for(const auto &ip : ips) + { + TC_Endpoint theEp = ep; + theEp.setHost(ip); + + v.push_back(EndpointInfo::toEndpointF(theEp, nodeName)); + } + + return v; + } + else if (host == "::1") + { + vector v; + vector ips = TC_Socket::getLocalHosts(AF_INET6, false); + + for(const auto &ip : ips) + { + TC_Endpoint theEp = ep; + theEp.setHost(ip); + + v.push_back(EndpointInfo::toEndpointF(theEp, nodeName)); + } + + return v; + } + else if (host == "*") + { + vector v; + { + vector ips = TC_Socket::getLocalHosts(AF_INET, false); + + for (const auto &ip: ips) + { + TC_Endpoint theEp = ep; + theEp.setHost(ip); + + v.push_back(EndpointInfo::toEndpointF(theEp, nodeName)); + } + } + + { + vector ips = TC_Socket::getLocalHosts(AF_INET6, false); + + for (const auto &ip: ips) + { + TC_Endpoint theEp = ep; + theEp.setHost(ip); + + v.push_back(EndpointInfo::toEndpointF(theEp, nodeName)); + } + } + + return v; + } + else + { + return {EndpointInfo::toEndpointF(ep, nodeName)}; + } +} + +string EndpointInfo::vectorEndpointFToStr(const vector &eps, bool complete) +{ + ostringstream os; + if(!complete) + { + for (size_t i = 0; i < eps.size(); i++) + { + os << eps[i].host << ":" << eps[i].port; + if (i != eps.size() - 1) + { + os << ","; + } + } + } + else + { + for (size_t i = 0; i < eps.size(); i++) + { + os << toEndpointF(eps[i]).toString(); + if (i != eps.size() - 1) + { + os << ":"; + } + } + } + return os.str(); +} + +vector EndpointInfo::strToVectorEndpointF(const string &str, const string &nodeName) +{ + vector eps = TC_Endpoint::sepEndpoint(str); + + //遍历转换格式 + vector epsF; + for (size_t i = 0; i < eps.size(); i++) + { + TC_Endpoint ep(eps[i]); + + epsF.push_back(EndpointInfo::toEndpointF(ep, nodeName)); + } + return epsF; +} + +map> EndpointInfo::toNodeEndpointF(const vector &eps) +{ + map> data; + for(auto ep : eps) + { + if(ep.nodeName.empty()) + { + //兼容旧框架, 没有赋值nodeName + ep.nodeName = ep.host; + } + + data[ep.nodeName].push_back(ep); + } + return data; +} + /////////////////////////////////////////////////////////// } diff --git a/servant/libservant/EndpointManager.cpp b/servant/libservant/EndpointManager.cpp index bbb3fc84..249afa58 100644 --- a/servant/libservant/EndpointManager.cpp +++ b/servant/libservant/EndpointManager.cpp @@ -58,7 +58,7 @@ QueryEpBase::QueryEpBase(Communicator * pComm, bool bFirstNetThread,bool bInterf void QueryEpBase::callback_findObjectById4All(Int32 ret, const vector& activeEp, const vector& inactiveEp) { - TLOGTARS("[callback_findObjectById4All _objName:" << _objName << "|ret:" << ret + TLOGTARS("[callback_findObjectById4All objName:" << _objName << "|ret:" << ret << ",active:" << activeEp.size() << ",inactive:" << inactiveEp.size() << "]" << endl); @@ -67,14 +67,14 @@ void QueryEpBase::callback_findObjectById4All(Int32 ret, const vector void QueryEpBase::callback_findObjectById4All_exception(Int32 ret) { - TLOGERROR("[callback_findObjectById4All_exception _objName:" << _objName << "|ret:" << ret << "]" << endl); + TLOGTARS("[callback_findObjectById4All_exception objName:" << _objName << "|ret:" << ret << "]" << endl); doEndpointsExp(ret); } void QueryEpBase::callback_findObjectById4Any(Int32 ret, const vector& activeEp, const vector& inactiveEp) { - TLOGTARS("[callback_findObjectById4Any _objName:" << _objName << "|ret:" << ret + TLOGTARS("[callback_findObjectById4Any objName:" << _objName << "|ret:" << ret << ",active:" << activeEp.size() << ",inactive:" << inactiveEp.size() << "]" << endl); @@ -83,14 +83,14 @@ void QueryEpBase::callback_findObjectById4Any(Int32 ret, const vector void QueryEpBase::callback_findObjectById4Any_exception(Int32 ret) { - TLOGERROR("[callback_findObjectById4Any_exception _objName:" << _objName << "|ret:" << ret << "]" << endl); + TLOGTARS("[callback_findObjectById4Any_exception objName:" << _objName << "|ret:" << ret << "]" << endl); doEndpointsExp(ret); } void QueryEpBase::callback_findObjectByIdInSameGroup(Int32 ret, const vector& activeEp, const vector& inactiveEp) { - TLOGTARS("[callback_findObjectByIdInSameGroup _objName:" << _objName << "|ret:"< &activeEp, const vector & inactiveEp) { - TLOGTARS("[callback_findObjectByIdInSameSet _objName:" << _objName << "|ret:" << ret + TLOGTARS("[callback_findObjectByIdInSameSet objName:" << _objName << "|ret:" << ret << ",active:" << activeEp.size() << ",inactive:" << inactiveEp.size() << "]" << endl); @@ -115,14 +115,14 @@ void QueryEpBase::callback_findObjectByIdInSameSet( Int32 ret, const vector &activeEp, const vector &inactiveEp) { - TLOGTARS("[callback_findObjectByIdInSameStation _objName:" << _objName << "|ret:" << ret + TLOGTARS("[callback_findObjectByIdInSameStation objName:" << _objName << "|ret:" << ret << ",active:" << activeEp.size() << ",inactive:" << inactiveEp.size() << "]" << endl); @@ -131,12 +131,12 @@ void QueryEpBase::callback_findObjectByIdInSameStation( Int32 ret, const vector< void QueryEpBase::callback_findObjectByIdInSameStation_exception( Int32 ret) { - TLOGERROR("[callback_findObjectByIdInSameStation_exception _objName:" << _objName << "|ret:" << ret << "]" << endl); + TLOGTARS("[callback_findObjectByIdInSameStation_exception objName:" << _objName << ", ret:" << ret << "]" << endl); doEndpointsExp(ret); } -int QueryEpBase::setLocatorPrx(QueryFPrx prx) +int QueryEpBase::setLocatorPrx(const QueryFPrx& prx) { _queryFPrx = prx; @@ -153,21 +153,46 @@ bool QueryEpBase::init(const string & sObjName, const string& setName, bool root _rootServant = rootServant; - if(sObjName.find("UdpIpv6Obj") != string::npos) - { - LOG_CONSOLE_DEBUG << "QueryEpBase::init sObjName:" << sObjName << ", sLocator:" << _locator << ", setName:" << setName << ", rootServant: " << rootServant << endl; - } setObjName(sObjName); return true; } +void QueryEpBase::loadFromCache() +{ + string sLocatorKey = _locator; + + //如果启用set,则获取按set分组的缓存 + if (_communicator->getClientConfig().SetOpen) + { + sLocatorKey += "_" + _communicator->getClientConfig().SetDivision; + } + + string objName = _objName + string(_invokeSetId.empty() ? "" : ":") + _invokeSetId; + + string sEndpoints = AppCache::getInstance()->get(objName, sLocatorKey); + string sInactiveEndpoints = AppCache::getInstance()->get("inactive_" + objName, sLocatorKey); + + setEndpoints(sEndpoints,_activeEndpoints); + setEndpoints(sInactiveEndpoints,_inactiveEndpoints); + + if(!_activeEndpoints.empty()) + { + _valid = true; + } + + if((!_activeEndpoints.empty() || !_inactiveEndpoints.empty())) + { + //非直接指定端口, 且从cache中能查到服务端口的, 不需要通知所有ObjectProxy更新地址 + notifyEndpoints(_activeEndpoints,_inactiveEndpoints,true); + } +} + void QueryEpBase::setObjName(const string & sObjName) { string::size_type pos = sObjName.find_first_of('@'); string sEndpoints; - string sInactiveEndpoints; if (pos != string::npos) { @@ -176,7 +201,7 @@ void QueryEpBase::setObjName(const string & sObjName) sEndpoints = sObjName.substr(pos + 1); - pos = _objName.find_first_of("#"); + pos = _objName.find_first_of('#'); if(pos != string::npos) { @@ -186,13 +211,21 @@ void QueryEpBase::setObjName(const string & sObjName) _direct = true; //如果就是主控, 则认为是非direct - size_t pos = _locator.find_first_not_of('@'); + pos = _locator.find_first_not_of('@'); if(pos != string::npos && _objName == _locator.substr(0, pos)) { _direct = false; } _valid = true; + + setEndpoints(sEndpoints, _activeEndpoints); + + if(!_activeEndpoints.empty()) + { + //非直接指定端口, 且从cache中能查到服务端口的, 不需要通知所有ObjectProxy更新地址 + notifyEndpoints(_activeEndpoints, _inactiveEndpoints, true); + } } else { @@ -205,11 +238,11 @@ void QueryEpBase::setObjName(const string & sObjName) if(_locator.find_first_not_of('@') == string::npos) { - TLOGERROR("[QueryEpBase::setObjName locator is not valid,_locator:" << _locator << "]" << endl); - throw TarsRegistryException("locator is not valid,_locator:" + _locator); + TLOGERROR("[QueryEpBase::setObjName locator is not valid, locator:" << _locator << "]" << endl); + throw TarsRegistryException("locator is not valid, locator:" + _locator); } - pos = _objName.find_first_of("#"); + pos = _objName.find_first_of('#'); if(pos != string::npos) { _objName = _objName.substr(0, pos); @@ -218,37 +251,15 @@ void QueryEpBase::setObjName(const string & sObjName) _queryFPrx = _communicator->stringToProxy(_locator); _queryFPrx->tars_open_keepalive(false); - string sLocatorKey = _locator; - - //如果启用set,则获取按set分组的缓存 - if(ClientConfig::SetOpen) - { - sLocatorKey += "_" + ClientConfig::SetDivision; - } - - string objName = _objName + string(_invokeSetId.empty() ? "" : ":") + _invokeSetId; - //[间接连接]第一次使用cache,如果是接口级请求则不从缓存读取 if(!_interfaceReq) { - sEndpoints = AppCache::getInstance()->get(objName,sLocatorKey); - sInactiveEndpoints = AppCache::getInstance()->get("inactive_"+objName,sLocatorKey); + loadFromCache(); } } - setEndpoints(sEndpoints,_activeEndpoints); - setEndpoints(sInactiveEndpoints,_inactiveEndpoints); - - if(!_activeEndpoints.empty()) - { - _valid = true; - } - - if((!_activeEndpoints.empty() || !_inactiveEndpoints.empty())) - { - //非直接指定端口, 且从cache中能查到服务端口的, 不需要通知所有ObjectProxy更新地址 - notifyEndpoints(_activeEndpoints,_inactiveEndpoints,true); - } + //重置刷新时间, 保证会马上刷新主控ip list + _refreshTime = 0; } void QueryEpBase::setEndpoints(const string & sEndpoints, set & setEndpoints) @@ -381,31 +392,31 @@ void QueryEpBase::refreshReg(GetEndpointType type, const string & sName) { case E_ALL: { - iRet = _queryFPrx->findObjectById4Any(_objName,activeEp,inactiveEp, ServerConfig::Context); + iRet = _queryFPrx->findObjectById4Any(_objName,activeEp,inactiveEp, _communicator->getClientConfig().Context); break; } case E_STATION: { - iRet = _queryFPrx->findObjectByIdInSameStation(_objName,sName,activeEp,inactiveEp, ServerConfig::Context); + iRet = _queryFPrx->findObjectByIdInSameStation(_objName,sName,activeEp,inactiveEp, _communicator->getClientConfig().Context); break; } case E_SET: { - iRet = _queryFPrx->findObjectByIdInSameSet(_objName,sName,activeEp,inactiveEp, ServerConfig::Context); + iRet = _queryFPrx->findObjectByIdInSameSet(_objName,sName,activeEp,inactiveEp, _communicator->getClientConfig().Context); break; } case E_DEFAULT: default: { - if(ClientConfig::SetOpen || !_invokeSetId.empty()) + if(_communicator->getClientConfig().SetOpen || !_invokeSetId.empty()) { //指定set调用时,指定set的优先级最高 - string setId = _invokeSetId.empty()?ClientConfig::SetDivision:_invokeSetId; - iRet = _queryFPrx->findObjectByIdInSameSet(_objName,setId,activeEp,inactiveEp, ServerConfig::Context); + string setId = _invokeSetId.empty()?_communicator->getClientConfig().SetDivision:_invokeSetId; + iRet = _queryFPrx->findObjectByIdInSameSet(_objName,setId,activeEp,inactiveEp, _communicator->getClientConfig().Context); } else { - iRet = _queryFPrx->findObjectByIdInSameGroup(_objName,activeEp,inactiveEp, ServerConfig::Context); + iRet = _queryFPrx->findObjectByIdInSameGroup(_objName,activeEp,inactiveEp, _communicator->getClientConfig().Context); } break; } @@ -418,45 +429,65 @@ void QueryEpBase::refreshReg(GetEndpointType type, const string & sName) { case E_ALL: { - _queryFPrx->async_findObjectById4Any(this,_objName, ServerConfig::Context); +#if TARS_STD_SHARED_PTR + _queryFPrx->async_findObjectById4Any(shared_from_this(),_objName, _communicator->getClientConfig().Context); +#else + _queryFPrx->async_findObjectById4Any(this,_objName, _communicator->getClientConfig().Context); +#endif break; } case E_STATION: { - _queryFPrx->async_findObjectByIdInSameStation(this,_objName,sName, ServerConfig::Context); +#if TARS_STD_SHARED_PTR + _queryFPrx->async_findObjectByIdInSameStation(shared_from_this(),_objName,sName, _communicator->getClientConfig().Context); +#else + _queryFPrx->async_findObjectByIdInSameStation(this,_objName,sName, _communicator->getClientConfig().Context); +#endif break; } case E_SET: { - _queryFPrx->async_findObjectByIdInSameSet(this,_objName,sName, ServerConfig::Context); +#if TARS_STD_SHARED_PTR + _queryFPrx->async_findObjectByIdInSameSet(shared_from_this(),_objName,sName, _communicator->getClientConfig().Context); +#else + _queryFPrx->async_findObjectByIdInSameSet(this,_objName,sName, _communicator->getClientConfig().Context); +#endif break; } case E_DEFAULT: default: { - if(ClientConfig::SetOpen || !_invokeSetId.empty()) + if(_communicator->getClientConfig().SetOpen || !_invokeSetId.empty()) { //指定set调用时,指定set的优先级最高 - string setId = _invokeSetId.empty()?ClientConfig::SetDivision:_invokeSetId; - _queryFPrx->async_findObjectByIdInSameSet(this,_objName,setId, ServerConfig::Context); + string setId = _invokeSetId.empty()?_communicator->getClientConfig().SetDivision:_invokeSetId; +#if TARS_STD_SHARED_PTR + _queryFPrx->async_findObjectByIdInSameSet(shared_from_this(),_objName,setId, _communicator->getClientConfig().Context); +#else + _queryFPrx->async_findObjectByIdInSameSet(this,_objName,setId, _communicator->getClientConfig().Context); +#endif } else { - _queryFPrx->async_findObjectByIdInSameGroup(this,_objName, ServerConfig::Context); +#if TARS_STD_SHARED_PTR + _queryFPrx->async_findObjectByIdInSameGroup(shared_from_this(),_objName, _communicator->getClientConfig().Context); +#else + _queryFPrx->async_findObjectByIdInSameGroup(this,_objName, _communicator->getClientConfig().Context); +#endif } break; } }//end switch } } - catch(TC_Exception & ex) + catch(exception & ex) { - TLOGERROR("[QueryEpBase::refreshReg obj:"<<_objName<<"exception:"<& activeEp, const vector& activeEp, const vectorgetClientConfig().SetOpen) { - sLocatorKey += "_" + ClientConfig::SetDivision; + sLocatorKey += "_" + _communicator->getClientConfig().SetDivision; } string objName = _objName + string(_invokeSetId.empty()?"":":") + _invokeSetId; if(bInactive) @@ -1058,7 +1095,7 @@ AdapterProxy* EndpointManager::getConHashProxyForWeight(int64_t hashCode, bool b { if(_vRegProxys.empty()) { - TLOGERROR("[EndpointManager::getConHashProxyForWeight _vRegProxys is empty], bStatic:" << bStatic << endl); + TLOGERROR("[EndpointManager::getConHashProxyForWeight _vRegProxys is empty, bStatic:" << bStatic << "]" << endl); return NULL; } @@ -1070,7 +1107,7 @@ AdapterProxy* EndpointManager::getConHashProxyForWeight(int64_t hashCode, bool b int64_t iEnd = TNOWMS; - TLOGTARS("[EndpointManager::getConHashProxyForWeight update bStatic:" << bStatic << "|_objName:" << _objName << "|timecost(ms):" << (iEnd - iBegin) << endl); + TLOGTARS("[EndpointManager::getConHashProxyForWeight update bStatic:" << bStatic << ", objName:" << _objName << ", timecost(ms):" << (iEnd - iBegin) << endl); } while(_consistentHashWeight.size() > 0) @@ -1108,7 +1145,7 @@ AdapterProxy* EndpointManager::getConHashProxyForWeight(int64_t hashCode, bool b if (_indexActiveProxys.empty()) { - TLOGERROR("[EndpointManager::getConHashProxyForNormal _activeEndpoints is empty]" << endl); + TLOGERROR("[EndpointManager::getConHashProxyForNormal activeEndpoints is empty]" << endl); return NULL; } } @@ -1198,7 +1235,7 @@ void EndpointManager::updateHashProxyWeighted(bool bStatic) { if(_vRegProxys.size() <= 0) { - TLOGERROR("[EndpointManager::updateHashProxyWeighted _vRegProxys is empty], bStatic:" << bStatic << endl); + TLOGERROR("[EndpointManager::updateHashProxyWeighted vRegProxys is empty, bStatic:" << bStatic << "]" << endl); return ; } @@ -1221,9 +1258,9 @@ void EndpointManager::updateHashProxyWeighted(bool bStatic) _vRegProxys[i]->resetWeightChanged(); } - if(vRegProxys.size() <= 0) + if(vRegProxys.empty()) { - TLOGERROR("[EndpointManager::updateHashProxyWeighted vRegProxys is empty], bStatic:" << bStatic << endl); + TLOGERROR("[EndpointManager::updateHashProxyWeighted vRegProxys is empty, bStatic:" << bStatic << "]" << endl); return ; } @@ -1288,7 +1325,7 @@ void EndpointManager::updateHashProxyWeighted(bool bStatic) } } - TLOGTARS("EndpointManager::updateHashProxyWeighted bStatic:" << bStatic << "|_objName:" << _objName << "|endpoint:" << vRegProxys[i]->endpoint().desc() << "|iWeight:" << vRegProxys[i]->getWeight() << "|iWeightR:" << iWeight << "|iIndex:" << vIndex[i] << endl); + TLOGTARS("EndpointManager::updateHashProxyWeighted bStatic:" << bStatic << ", objName:" << _objName << ", endpoint:" << vRegProxys[i]->endpoint().desc() << ", iWeight:" << vRegProxys[i]->getWeight() << ", iWeightR:" << iWeight << ", iIndex:" << vIndex[i] << endl); } for(size_t i = 0; i < iMaxRouterR; i++) @@ -1326,7 +1363,7 @@ void EndpointManager::updateConHashProxyWeighted(bool bStatic, mapgetCommunicator()->getClientConfig().SetOpen || !_invokeSetId.empty()) { //指定set调用时,指定set的优先级最高 - _invokeSetId = _invokeSetId.empty()?ClientConfig::SetDivision:_invokeSetId; + _invokeSetId = _invokeSetId.empty()?pCommunicatorEpoll->getCommunicator()->getClientConfig().SetDivision:_invokeSetId; _isInvokeBySet = true; } } @@ -274,27 +273,17 @@ void ObjectProxy::doInvokeException(ReqMessage * msg) } catch(exception & e) { - TLOGERROR("[ObjectProxy::doInvokeException exp:"<request.sServantName << ":" << msg->request.sFuncName << " error: " << e.what() <request.sServantName << ":" << msg->request.sFuncName << ", error" << endl); } } else { - //先确保adapter 非null - if (msg->adapter) - { - //异步回调,放入回调处理线程中 - _communicatorEpoll->pushAsyncThreadQueue(msg); - } - else - { - TLOGERROR("[ObjectProxy::doInvokeException push adapter is null|" << __LINE__ << endl); - delete msg; - msg = NULL; - } + _communicatorEpoll->pushAsyncThreadQueue(msg); + TLOGERROR("[ObjectProxy::doInvokeException " << msg->request.sServantName << ":" << msg->request.sFuncName << ", ret: " << msg->response->iRet << endl); } } else diff --git a/servant/libservant/PropertyReport.cpp b/servant/libservant/PropertyReport.cpp index b5b77f90..326e8a24 100644 --- a/servant/libservant/PropertyReport.cpp +++ b/servant/libservant/PropertyReport.cpp @@ -63,6 +63,10 @@ void PropertyReport::distr::set(int o) ++_result[n]; } + else + { + ++_max; + } } string PropertyReport::distr::get() @@ -81,6 +85,12 @@ string PropertyReport::distr::get() { _result[i] = 0; } + if (!s.empty()) + { + s += ","; + } + s += "max|" + TC_Common::tostr(_max); + _max = 0; return s; } diff --git a/servant/libservant/RemoteConfig.cpp b/servant/libservant/RemoteConfig.cpp index aaf4d0c5..8fe3068a 100755 --- a/servant/libservant/RemoteConfig.cpp +++ b/servant/libservant/RemoteConfig.cpp @@ -18,45 +18,49 @@ #include "util/tc_file.h" #include "servant/Communicator.h" #include "servant/RemoteNotify.h" +#include "servant/ConfigF.h" #include "servant/Application.h" #include namespace tars { -int RemoteConfig::setConfigInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string& basePath,const string& setdivision, int maxBakNum) +int +RemoteConfig::setConfigInfo(const CommunicatorPtr &comm, const string &obj, const string &app, const string &serverName, + const string &basePath, const string &setdivision, int maxBakNum) { - _comm = comm; - if(!obj.empty()) + TC_LockT lock(_mutex); + + _comm = comm; + if (!obj.empty()) { - _configPrx = _comm->stringToProxy(obj); + _configPrx = _comm->stringToProxy(obj); _configPrx->tars_open_keepalive(false); } - _app = app; - _serverName = serverName; - _basePath = basePath; - _maxBakNum = maxBakNum; - _setdivision = setdivision; + _app = app; + _serverName = serverName; + _basePath = basePath; + _maxBakNum = maxBakNum; + _setdivision = setdivision; return 0; } -bool RemoteConfig::addConfig(const string & sFileName, string &buffer, bool bAppConfigOnly) +bool RemoteConfig::addConfig(const string &sFileName, string &buffer, bool bAppConfigOnly) { TC_LockT lock(_mutex); try { - string sFullFileName = _basePath + FILE_SEP + sFileName; + string sFullFileName = TC_File::simplifyDirectory(_basePath + FILE_SEP + sFileName); string newFile = getRemoteFile(sFileName, bAppConfigOnly); if (newFile.empty() || !TC_File::isFileExist(newFile))//拉取不到配置中心的配置文件 { - if(!TC_File::isFileExist(newFile)) //获取本地配置成功,返回成功,但需要告警一下。 + if (TC_File::isFileExist(sFullFileName)) //获取本地配置成功,返回成功,但需要告警一下。 { - buffer = "[fail] get remote config:" + sFileName + "fail,use the local config."; - + buffer = "[fail] get remote config:" + sFileName + "fail,use the local config: " + sFullFileName; return true; } throw runtime_error("access file error:" + newFile); @@ -68,7 +72,7 @@ bool RemoteConfig::addConfig(const string & sFileName, string &buffer, bool bApp { if (TC_File::isFileExist(index2file(sFullFileName, i))) { - localRename(index2file(sFullFileName, i), index2file(sFullFileName, i+1)); + localRename(index2file(sFullFileName, i), index2file(sFullFileName, i + 1)); } } @@ -80,14 +84,14 @@ bool RemoteConfig::addConfig(const string & sFileName, string &buffer, bool bApp localRename(newFile, sFullFileName); - assert(TC_File::isFileExist(sFullFileName)); + assert(TC_File::isFileExist(sFullFileName)); //assert(!access(sFullFileName.c_str(), R_OK)); buffer = "[succ] get remote config:" + sFileName; return true; } - catch (std::exception& e) + catch (std::exception &e) { buffer = "[fail] get remote config '" + sFileName + "' error:" + string(e.what()); } @@ -103,58 +107,61 @@ string RemoteConfig::getRemoteFile(const string &sFileName, bool bAppConfigOnly) { if (_configPrx) { - string stream; - int ret = -1; - - for(int i = 0; i < 2;i++) - { - try - { - if(_setdivision.empty()) - { - ret = _configPrx->loadConfig(_app, (bAppConfigOnly ? "" : _serverName), sFileName, stream, ServerConfig::Context); - } - else - { - struct ConfigInfo confInfo; - confInfo.appname = _app; - confInfo.servername = (bAppConfigOnly ? "" : _serverName); - confInfo.filename = sFileName; - confInfo.bAppOnly = bAppConfigOnly; - confInfo.setdivision = _setdivision; - ret = _configPrx->loadConfigByInfo(confInfo,stream, ServerConfig::Context); - } - - break; - }catch(std::exception& e){ - // - }catch (...){ - // - } - } - - if (ret != 0 || stream.empty()) - { - throw runtime_error("remote config file is empty:" + sFileName); - } - - string newFile = _basePath + FILE_SEP + sFileName + "." + TC_Common::tostr(time(NULL)); + string stream; + int ret = -1; + + for (int i = 0; i < 2; i++) + { + try + { + if (_setdivision.empty()) + { + ret = _configPrx->loadConfig(_app, (bAppConfigOnly ? "" : _serverName), sFileName, stream, _comm->getClientConfig().Context); + } else + { + struct ConfigInfo confInfo; + confInfo.appname = _app; + confInfo.servername = (bAppConfigOnly ? "" : _serverName); + confInfo.filename = sFileName; + confInfo.bAppOnly = bAppConfigOnly; + confInfo.setdivision = _setdivision; + ret = _configPrx->loadConfigByInfo(confInfo, stream, _comm->getClientConfig().Context); + } + + break; + } catch (std::exception &e) + { + TLOG_ERROR("error:" << e.what() << endl); + // + } catch (...) + { + // + } + } + + if (ret != 0 || stream.empty()) + { + TLOG_ERROR("remote config file is empty:" + sFileName << endl); + return ""; +// throw runtime_error("remote config file is empty:" + sFileName); + } + + string newFile = TC_File::simplifyDirectory( _basePath + FILE_SEP + sFileName + "." + TC_Common::tostr(time(NULL))); std::ofstream out(newFile.c_str()); - + string result; if (out) { out << stream;//如果硬盘满了,是否能写入成功需要进行判断。 out.flush(); - if(out.bad()) + if (out.bad()) { out.close(); - result = "[fail] copy stream to disk error." ; + result = "[fail] copy stream to disk error."; RemoteNotify::getInstance()->report(result); return ""; - } - else + } else { out.close(); return newFile; @@ -164,12 +171,12 @@ string RemoteConfig::getRemoteFile(const string &sFileName, bool bAppConfigOnly) return ""; } -string RemoteConfig::index2file(const string & sFullFileName, int index) +string RemoteConfig::index2file(const string &sFullFileName, int index) { - return sFullFileName + "." + TC_Common::tostr(index) + ".bak"; + return sFullFileName + "." + TC_Common::tostr(index) + ".bak"; } -void RemoteConfig::localRename(const string& oldFile, const string& newFile) +void RemoteConfig::localRename(const string &oldFile, const string &newFile) { #if TARGET_PLATFORM_WINDOWS //by goodenpei,windows下面先remove后rename,否则rename会失败 @@ -184,7 +191,7 @@ void RemoteConfig::localRename(const string& oldFile, const string& newFile) } } -string RemoteConfig::recoverSysConfig(const string & sFullFileName) +string RemoteConfig::recoverSysConfig(const string &sFullFileName) { try { @@ -198,7 +205,7 @@ string RemoteConfig::recoverSysConfig(const string & sFullFileName) } } } - catch (std::exception& e) + catch (std::exception &e) { return "[fail] recover config error:" + string(e.what()); } diff --git a/servant/libservant/RemoteLogger.cpp b/servant/libservant/RemoteLogger.cpp index c7c6f4d1..00b18d63 100644 --- a/servant/libservant/RemoteLogger.cpp +++ b/servant/libservant/RemoteLogger.cpp @@ -17,11 +17,11 @@ #include "servant/RemoteLogger.h" #include "servant/Communicator.h" #include "servant/Application.h" +#include "servant/LogF.h" namespace tars { -//int RollWriteT::_dyeingThread = 0; int TimeWriteT::_dyeing = 0; ///////////////////////////////////////////////////////////////////////////////////// @@ -84,7 +84,8 @@ void RollWriteT::operator()(ostream &of, const deque > &ds) { try { - _logPrx->logger(DYEING_DIR, DYEING_FILE, "roll", "%Y%m%d", vRemoteDyeing, ServerConfig::Context); + + _logPrx->logger(DYEING_DIR, DYEING_FILE, "roll", "%Y%m%d", vRemoteDyeing, _context); } catch(exception &ex) { @@ -93,14 +94,19 @@ void RollWriteT::operator()(ostream &of, const deque > &ds) } } -void RollWriteT::setDyeingLogInfo(const string &sApp, const string &sServer, const string & sLogPath, int iMaxSize, int iMaxNum, const LogPrx &logPrx, const string &sLogObj) +void RollWriteT::setDyeingLogInfo(const string &sApp, const string &sServer, const string & sLogPath, int iMaxSize, int iMaxNum, const LogPrx &logPrx) { _app = sApp; _server = sServer; _logPath = sLogPath; _maxSize = iMaxSize; _maxNum = iMaxNum; + _logPrx = logPrx; + if(_logPrx) + { + _context["node_name"] = _logPrx->tars_communicator()->getClientConfig().NodeName; + } } @@ -108,7 +114,9 @@ void RollWriteT::setDyeingLogInfo(const string &sApp, const string &sServer, con LocalRollLogger::~LocalRollLogger() { - for(auto e : _logger_ex) + terminate(); + + for(const auto& e : _logger_ex) { delete e.second; } @@ -126,6 +134,11 @@ void LocalRollLogger::terminate() void LocalRollLogger::setLogInfo(const string &sApp, const string &sServer, const string &sLogpath, int iMaxSize, int iMaxNum, const CommunicatorPtr &comm, const string &sLogObj) { + if (_local.isStart()) + { + return; + } + _app = sApp; _server = sServer; _logpath = sLogpath; @@ -141,7 +154,7 @@ void LocalRollLogger::setLogInfo(const string &sApp, const string &sServer, cons //生成目录 TC_File::makeDirRecursive(_logpath + FILE_SEP + _app + FILE_SEP + _server); - _local.start(1); + _local.start(); //初始化本地循环日志 _logger.init(_logpath + FILE_SEP + _app + FILE_SEP + _server + FILE_SEP + _app + "." + _server, iMaxSize, iMaxNum); @@ -152,7 +165,7 @@ void LocalRollLogger::setLogInfo(const string &sApp, const string &sServer, cons sync(false); //设置染色日志信息 - _logger.getWriteT().setDyeingLogInfo(sApp, sServer, sLogpath, iMaxSize, iMaxNum, _logPrx, sLogObj); + _logger.getWriteT().setDyeingLogInfo(sApp, sServer, sLogpath, iMaxSize, iMaxNum, _logPrx); } @@ -223,7 +236,7 @@ LocalRollLogger::RollLogger *LocalRollLogger::logger(const string &suffix) logger->modFlag(TC_DayLogger::HAS_TIME|TC_DayLogger::HAS_LEVEL|TC_DayLogger::HAS_PID, true); //设置染色日志信息 - logger->getWriteT().setDyeingLogInfo(_app, _server, _logpath, _logger.getMaxSize(), _logger.getMaxSize(), _logPrx, _logObj); + logger->getWriteT().setDyeingLogInfo(_app, _server, _logpath, _logger.getMaxSize(), _logger.getMaxSize(), _logPrx); _logger_ex[suffix] = logger; @@ -234,8 +247,8 @@ LocalRollLogger::RollLogger *LocalRollLogger::logger(const string &suffix) TarsLoggerThread::TarsLoggerThread() { - _local.start(1); - _remote.start(1); + _local.start(); + _remote.start(); } TarsLoggerThread::~TarsLoggerThread() @@ -287,63 +300,65 @@ void RemoteTimeWriteT::setTimeWriteT(TimeWriteT *pTimeWrite) void RemoteTimeWriteT::operator()(ostream &of, const deque > &buffer) { - const static uint32_t len = 2000; + //此处传递set信息到远程logserver + LogInfo stInfo; + stInfo.appname = _timeWrite->_app; + stInfo.servername = _timeWrite->_server; + stInfo.sFilename = _timeWrite->_file; + stInfo.sFormat = _timeWrite->_format; + stInfo.setdivision = _timeWrite->_setDivision; + stInfo.bHasSufix = _timeWrite->_hasSufix; + stInfo.bHasAppNamePrefix = _timeWrite->_hasAppNamePrefix; + stInfo.sConcatStr = _timeWrite->_concatStr; + stInfo.bHasSquareBracket = _timeWrite->_hasSquareBracket; + stInfo.sSepar = _timeWrite->_separ; + stInfo.sLogType = _timeWrite->_logType; + +// const static uint32_t len = 2000; //写远程日志 if(_timeWrite->_logPrx && !buffer.empty()) { - //大于50w条, 直接抛弃掉,否则容易导致内存泄漏 - if(buffer.size() > 500000) - { - _timeWrite->writeError(buffer); - return; - } - +// //大于50w条, 直接抛弃掉,否则容易导致内存泄漏 +// if(buffer.size() > 500000) +// { +// _timeWrite->writeError(buffer); +// return; +// } vector v; - v.reserve(len); - deque >::const_iterator it = buffer.begin(); + size_t len = 0; + deque>::const_iterator it = buffer.begin(); while(it != buffer.end()) { + len += it->second.size(); + v.push_back(it->second); ++it; //每次最多同步len条 - if(v.size() >= len) +// if(v.size() >= len) + if(len > 5*1024*1024 || v.size() > 200) { - sync2remote(v); + //>5M 或超过200条 就要传输了! + sync2remote(stInfo, v); v.clear(); - v.reserve(len); } } - if(v.size() > 0) + if(!v.empty()) { - sync2remote(v); + sync2remote(stInfo, v); } } } -void RemoteTimeWriteT::sync2remote(const vector &v) +void RemoteTimeWriteT::sync2remote(const LogInfo &stInfo, const vector &v) { try { - //此处传递set信息到远程logserver - LogInfo stInfo; - stInfo.appname = _timeWrite->_app; - stInfo.servername = _timeWrite->_server; - stInfo.sFilename = _timeWrite->_file; - stInfo.sFormat = _timeWrite->_format; - stInfo.setdivision = _timeWrite->_setDivision; - stInfo.bHasSufix = _timeWrite->_hasSufix; - stInfo.bHasAppNamePrefix = _timeWrite->_hasAppNamePrefix; - stInfo.sConcatStr = _timeWrite->_concatStr; - stInfo.bHasSquareBracket = _timeWrite->_hasSquareBracket; - stInfo.sSepar = _timeWrite->_separ; - stInfo.sLogType = _timeWrite->_logType; - - _timeWrite->_logPrx->loggerbyInfo(stInfo,v, ServerConfig::Context); + _timeWrite->_logPrx->loggerbyInfo(stInfo,v, _timeWrite->_logPrx->tars_communicator()->getClientConfig().Context); if (_timeWrite->_reportSuccPtr) { @@ -365,7 +380,7 @@ void RemoteTimeWriteT::sync2remoteDyeing(const vector &v) { try { - _timeWrite->_logPrx->logger(DYEING_DIR, DYEING_FILE, "", _timeWrite->_format, v, ServerConfig::Context); + _timeWrite->_logPrx->logger(DYEING_DIR, DYEING_FILE, "", _timeWrite->_format, v, _timeWrite->_logPrx->tars_communicator()->getClientConfig().Context); } catch(exception &ex) { @@ -507,7 +522,7 @@ void TimeWriteT::operator()(ostream &of, const deque > &buf { try { - _logPrx->logger(DYEING_DIR, DYEING_FILE, "day", "%Y%m%d", vDyeingLog, ServerConfig::Context); + _logPrx->logger(DYEING_DIR, DYEING_FILE, "day", "%Y%m%d", vDyeingLog, _logPrx->tars_communicator()->getClientConfig().Context); } catch(exception &ex) { @@ -645,7 +660,7 @@ void RemoteTimeLogger::initTimeLogger(TimeLogger *pTimeLogger, const string &sFi PropertyReportPtr reportFailPtr = NULL; if (_remote && _logStatReport && _comm) { - string sKey = _app + "." + _server + "." + sFile; + string sKey = sFile; reportSuccPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_succ", PropertyReport::sum()); reportFailPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_fail", PropertyReport::sum()); } @@ -715,7 +730,7 @@ void RemoteTimeLogger::initTimeLogger(TimeLogger *pTimeLogger,const string &sApp PropertyReportPtr reportFailPtr = NULL; if (_remote && _logStatReport && _comm) { - string sKey = _app + "." + _server + "." + sFile; + string sKey = sFile; reportSuccPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_succ", PropertyReport::sum()); reportFailPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_fail", PropertyReport::sum()); } diff --git a/servant/libservant/RemoteNotify.cpp b/servant/libservant/RemoteNotify.cpp index d45940c8..52a9177d 100644 --- a/servant/libservant/RemoteNotify.cpp +++ b/servant/libservant/RemoteNotify.cpp @@ -15,14 +15,13 @@ */ #include "servant/RemoteNotify.h" -#include "servant/Communicator.h" #include "servant/RemoteLogger.h" #include "servant/Application.h" namespace tars { -int RemoteNotify::setNotifyInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string &sSetName, const string &nodeName) +int RemoteNotify::setNotifyInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string &sSetName) { _comm = comm; if(!obj.empty()) @@ -35,7 +34,6 @@ int RemoteNotify::setNotifyInfo(const CommunicatorPtr &comm, const string &obj, _setName = sSetName; _app = app; _serverName = serverName; - _nodeName = nodeName; return 0; } @@ -52,14 +50,14 @@ void RemoteNotify::report(const string &sResult, bool bSync) info.sSet = _setName; info.sThreadId = TC_Common::tostr(std::this_thread::get_id()); info.sMessage = sResult; - info.sNodeName = _nodeName; + info.sNodeName = _comm->getClientConfig().NodeName; if(!bSync) { - _notifyPrx->async_reportNotifyInfo(NULL, info, ServerConfig::Context); + _notifyPrx->async_reportNotifyInfo(NULL, info, _comm->getClientConfig().Context); } else { - _notifyPrx->reportNotifyInfo(info, ServerConfig::Context); + _notifyPrx->reportNotifyInfo(info, _comm->getClientConfig().Context); } } } @@ -87,8 +85,8 @@ void RemoteNotify::notify(NOTIFYLEVEL level, const string &sMessage) info.sThreadId = TC_Common::tostr(std::this_thread::get_id()); info.sMessage = sMessage; info.eLevel = level; - info.sNodeName = _nodeName; - _notifyPrx->async_reportNotifyInfo(NULL, info, ServerConfig::Context); + info.sNodeName = _comm->getClientConfig().NodeName; + _notifyPrx->async_reportNotifyInfo(NULL, info, _comm->getClientConfig().Context); } } catch(exception &ex) @@ -114,7 +112,7 @@ void RemoteNotify::report(const string &sMessage, const string & app, const stri info.sSet = ""; info.sMessage = sMessage; info.sNodeName = sNodeName; - _notifyPrx->async_reportNotifyInfo(NULL, info, ServerConfig::Context); + _notifyPrx->async_reportNotifyInfo(NULL, info, _comm->getClientConfig().Context); } } catch(exception &ex) diff --git a/servant/libservant/Servant.cpp b/servant/libservant/Servant.cpp index a5c50c30..264c2235 100644 --- a/servant/libservant/Servant.cpp +++ b/servant/libservant/Servant.cpp @@ -27,7 +27,7 @@ namespace tars thread_local shared_ptr CallbackThreadData::g_sp; -Servant::Servant():_handle(NULL) +Servant::Servant() //:_handle(NULL) { } @@ -57,14 +57,29 @@ Application* Servant::getApplication() const return _application; } -void Servant::setHandle(TC_EpollServer::Handle* handle) +string Servant::getModuleName() +{ + return _application->getServerBaseInfo().Application + "." + _application->getServerBaseInfo().ServerName; +} + +void Servant::setHandle(const shared_ptr &handle) { _handle = handle; } -TC_EpollServer::Handle* Servant::getHandle() +shared_ptr Servant::getHandle() +{ + return _handle.lock(); +} + +void Servant::setModePython( bool forPython) { - return _handle; + _modePython = forPython; +} + +bool Servant::isPython() +{ + return _modePython; } int Servant::dispatch(CurrentPtr current, vector &buffer) @@ -85,9 +100,19 @@ int Servant::dispatch(CurrentPtr current, vector &buffer) } else { - TC_LockT lock(*this); - - ret = onDispatch(current, buffer); + if (isPython()) + { +// TC_LockT lock(*this); + BufferWrapper bufferWrapper; + ret = onDispatch(current, &bufferWrapper); + buffer.swap(bufferWrapper.buffer); + } + else + { + TC_LockT lock(*this); + + ret = onDispatch(current, buffer); + } } return ret; } diff --git a/servant/libservant/ServantHandle.cpp b/servant/libservant/ServantHandle.cpp index e0e5ff87..3b929408 100644 --- a/servant/libservant/ServantHandle.cpp +++ b/servant/libservant/ServantHandle.cpp @@ -23,7 +23,8 @@ #include "servant/BaseF.h" #include "servant/KeepAliveNodeF.h" #include "servant/Cookie.h" -#include "servant/Application.h" +#include "servant/RemoteNotify.h" + // #ifdef TARS_OPENTRACKING // #include "servant/text_map_carrier.h" // #endif @@ -34,229 +35,189 @@ namespace tars ///////////////////////////////////////////////////////////////////////// // ServantHandle::ServantHandle(Application *application) -: _application(application) + : _application(application) { - + } ServantHandle::~ServantHandle() { -// auto it = _servants.begin(); - -// while(it != _servants.end()) -// if(_servant) + try { - try + if(_servant) { _servant->destroy(); } - catch(exception &ex) - { - TLOGERROR("[ServantHandle::destroy error:" << ex.what() << "]" << endl); - } - catch(...) - { - TLOGERROR("[ServantHandle::destroy unknown exception error]" << endl); - } -// ++it; + } + catch (exception &ex) + { + TLOGERROR("[ServantHandle::destroy error:" << ex.what() << "]" << endl); + } + catch (...) + { + TLOGERROR("[ServantHandle::destroy unknown exception error]" << endl); } } +string ServantHandle::getModuleName() +{ + return _servant->getModuleName(); +} + void ServantHandle::handleAsyncResponse() { ReqMessagePtr resp; -// auto it = _servants.begin(); -// -// while (it != _servants.end()) -// if(_servant) + while (_servant->getResponseQueue().pop_front(resp)) { - while (_servant->getResponseQueue().pop_front(resp)) + try { - try + if (resp->response->iRet == TARSSERVERSUCCESS) { - if (resp->response->iRet == TARSSERVERSUCCESS) - { - _servant->doResponse(resp); - } - else if (resp->pObjectProxy == NULL) - { - _servant->doResponseNoRequest(resp); - } - else - { - _servant->doResponseException(resp); - } - } - catch (exception& e) + _servant->doResponse(resp); + } else if (resp->pObjectProxy == NULL) { - TLOGERROR("[ServantHandle::doResponse ex:" << e.what() << "]" << endl); - } - catch (...) + _servant->doResponseNoRequest(resp); + } else { - TLOGERROR("[ServantHandle::doResponse error]" << endl); + _servant->doResponseException(resp); } } - - //业务处理附加的自有消息 - try + catch (exception &e) { - _servant->doCustomMessage(false); - _servant->doCustomMessage(); - } - catch (exception& e) - { - TLOGERROR("[ServantHandle::doCustemMessage ex:" << e.what() << "]" << endl); + TLOGERROR("[ServantHandle::doResponse ex:" << e.what() << "]" << endl); } catch (...) { - TLOGERROR("[ServantHandle::doCustemMessage ex.]" << endl); + TLOGERROR("[ServantHandle::doResponse error]" << endl); } + } -// ++it; + //业务处理附加的自有消息 + try + { + _servant->doCustomMessage(false); + _servant->doCustomMessage(); + } + catch (exception &e) + { + TLOGERROR("[ServantHandle::doCustemMessage ex:" << e.what() << "]" << endl); + } + catch (...) + { + TLOGERROR("[ServantHandle::doCustemMessage ex.]" << endl); } + } void ServantHandle::handleCustomMessage(bool bExpectIdle) { -// for (auto it = _servants.begin(); it != _servants.end(); it++) -// if(_servant) + //业务处理附加的自有消息 + try { - //业务处理附加的自有消息 - try - { - _servant->doCustomMessage(bExpectIdle); - _servant->doCustomMessage(); - } - catch (exception& e) - { - TLOGERROR("[ServantHandle::doCustemMessage ex:" << e.what() << "]" << endl); - } - catch (...) - { - TLOGERROR("[ServantHandle::doCustemMessage ex.]" << endl); - } + _servant->doCustomMessage(bExpectIdle); + _servant->doCustomMessage(); + } + catch (exception &e) + { + TLOGERROR("[ServantHandle::doCustemMessage ex:" << e.what() << "]" << endl); + } + catch (...) + { + TLOGERROR("[ServantHandle::doCustemMessage ex.]" << endl); } } bool ServantHandle::allFilterIsEmpty() { -// auto it = _servants.begin(); - -// while (it != _servants.end()) -// if(_servant) - { - if (!_servant->getResponseQueue().empty()) - { - return false; - } -// ++it; - } - return true; + if (!_servant->getResponseQueue().empty()) + { + return false; + } + return true; } void ServantHandle::initialize() { - if(TC_CoroutineScheduler::scheduler()) - { - ServantProxyThreadData::getData()->_sched = TC_CoroutineScheduler::scheduler(); - } + if (TC_CoroutineScheduler::scheduler()) + { + ServantProxyThreadData::getData()->_sched = TC_CoroutineScheduler::scheduler(); + } _servant = _application->getServantHelper()->create(_bindAdapter->getName()); -// ServantPtr servant = _application->getServantHelper()->create(_bindAdapter->getName()); - -// if (servant) -// { -// _servants[servant->getName()] = servant; -// } -// else - if(!_servant) + if (!_servant) { - TLOGERROR("[ServantHandle initialize createServant ret null, for adapter `" +_bindAdapter->getName() + "`]" << endl); - cerr << "ServantHandle initialize createServant ret null, for adapter `" +_bindAdapter->getName() + "`]" << endl; + TLOGERROR("[ServantHandle initialize createServant ret null, for adapter `" + _bindAdapter->getName() + "`]" + << endl); + cerr << "ServantHandle initialize createServant ret null, for adapter `" + _bindAdapter->getName() + "`]" + << endl; - RemoteNotify::getInstance()->report("initialize createServant error: no adapter:" + _bindAdapter->getName()); + RemoteNotify::getInstance()->report("initialize createServant error: no adapter:" + _bindAdapter->getName()); - TC_Common::msleep(100); + TC_Common::msleep(100); - exit(-1); + exit(-1); } -// auto it = _servants.begin(); -// -// if(it == _servants.end()) -// { -// TLOGERROR("[initialize error: no servant exists]" << endl); -// -// RemoteNotify::getInstance()->report("initialize error: no servant exists."); -// -// TC_Common::msleep(100); -// -// exit(-1); -// } - -// while(it != _servants.end()) -// { - try - { - _servant->setHandle(this); + try + { + _servant->setHandle(shared_from_this()); - _servant->initialize(); + _servant->initialize(); - TLOGTARS("[" << _servant->getName() << " initialize]" << endl); - } - catch(exception &ex) - { - TLOGERROR("[initialize error:" << ex.what() << "]" << endl); + TLOGTARS("[" << _servant->getName() << " initialize]" << endl); + } + catch (exception &ex) + { + TLOGERROR("[initialize error:" << ex.what() << "]" << endl); - RemoteNotify::getInstance()->report("initialize error:" + string(ex.what())); + RemoteNotify::getInstance()->report("initialize error:" + string(ex.what())); - TC_Common::msleep(100); + TC_Common::msleep(100); - exit(-1); - } - catch(...) - { - TLOGERROR("[initialize unknown exception error]" << endl); + exit(-1); + } + catch (...) + { + TLOGERROR("[initialize unknown exception error]" << endl); - RemoteNotify::getInstance()->report("initialize unknown exception error"); + RemoteNotify::getInstance()->report("initialize unknown exception error"); - TC_Common::msleep(100); + TC_Common::msleep(100); - exit(-1); - } -// ++it; -// } + exit(-1); + } } void ServantHandle::heartbeat() { - time_t fcur = TNOW; - - if (abs(fcur - _bindAdapter->getHeartBeatTime()) > HEART_BEAT_INTERVAL) - { - _bindAdapter->setHeartBeatTime(fcur); - - TARS_KEEPALIVE(_bindAdapter->getName()); - - //上报连接数 比率 - if (_bindAdapter->_pReportConRate) - { - _bindAdapter->_pReportConRate->report((int)(_bindAdapter->getNowConnection() * 1000 / _bindAdapter->getMaxConns())); - } - - //有队列, 且队列长度>0才上报 - if (_bindAdapter->_pReportQueue) - { - _bindAdapter->_pReportQueue->report((int)_bindAdapter->getRecvBufferSize()); - } - } + time_t fcur = TNOW; + + if (abs(fcur - _bindAdapter->getHeartBeatTime()) > HEART_BEAT_INTERVAL) + { + _bindAdapter->setHeartBeatTime(fcur); + + _application->_keepAliveNodeFHelper->keepAlive(_bindAdapter->getName()); + + //上报连接数 比率 + if (_bindAdapter->_pReportConRate) + { + _bindAdapter->_pReportConRate->report( + (int) (_bindAdapter->getNowConnection() * 1000 / _bindAdapter->getMaxConns())); + } + + //有队列, 且队列长度>0才上报 + if (_bindAdapter->_pReportQueue) + { + _bindAdapter->_pReportQueue->report((int) _bindAdapter->getRecvBufferSize()); + } + } } CurrentPtr ServantHandle::createCurrent(const shared_ptr &data) { - CurrentPtr current = new Current(this); + CurrentPtr current (new Current(shared_from_this())); try { @@ -271,96 +232,84 @@ CurrentPtr ServantHandle::createCurrent(const shared_ptrgetBindAdapter()->isTarsProtocol()) + if (current->getBindAdapter()->isTarsProtocol()) { int64_t now = TNOWMS; - //数据在队列中的时间超过了客户端等待的时间(TARS协议) - if (current->_request.iTimeout > 0 && (now - data->recvTimeStamp()) > current->_request.iTimeout) - { - //上报超时数目 - if (data->adapter()->_pReportTimeoutNum) - data->adapter()->_pReportTimeoutNum->report(1); + //数据在队列中的时间超过了客户端等待的时间(TARS协议) + if (current->_request.iTimeout > 0 && (now - data->recvTimeStamp()) > current->_request.iTimeout) + { + //上报超时数目 + if (data->adapter()->_pReportTimeoutNum) + data->adapter()->_pReportTimeoutNum->report(1); TLOGERROR("[TARS][ServantHandle::handle queue timeout:" - << current->_request.sServantName << ", func:" - << current->_request.sFuncName << ", recv time:" - << data->recvTimeStamp() << ", queue timeout:" - << data->adapter()->getQueueTimeout() << ", timeout:" - << current->_request.iTimeout << ", now:" - << now << ", ip:" << data->ip() << ", port:" << data->port() << "]" << endl); + << current->_request.sServantName << ", func:" + << current->_request.sFuncName << ", recv time:" + << data->recvTimeStamp() << ", queue timeout:" + << data->adapter()->getQueueTimeout() << ", timeout:" + << current->_request.iTimeout << ", now:" + << now << ", ip:" << data->ip() << ", port:" << data->port() << "]" << endl); current->sendResponse(TARSSERVERQUEUETIMEOUT); - return NULL; - } - } + return NULL; + } + } - return current; + return current; } CurrentPtr ServantHandle::createCloseCurrent(const shared_ptr &data) { - CurrentPtr current = new Current(this); + CurrentPtr current ( new Current(shared_from_this())); - current->initializeClose(data); - current->setReportStat(false); - current->setCloseType(data->closeType()); - return current; + current->initializeClose(data); +// current->setReportStat(false); + current->setCloseType(data->closeType()); + return current; } void ServantHandle::handleClose(const shared_ptr &data) { - TLOGTARS("[ServantHandle::handleClose,adapter:" << data->adapter()->getName() << ",peer:" << data->ip() << ":" << data->port() << "]"<< endl); - - CurrentPtr current = createCloseCurrent(data); - -// auto sit = _servants.find(current->getServantName()); + TLOGTARS("[ServantHandle::handleClose,adapter:" << data->adapter()->getName() << ",peer:" << data->ip() << ":" + << data->port() << "]" << endl); -// if (sit == _servants.end()) -// { -// TLOGERROR("[TARS]ServantHandle::handleClose,adapter:" << data->adapter()->getName() << ",peer:" << data->ip() << ":" << data->port() << ", " << current->getServantName() << " not found" << endl); -// -// return; -// } -// -// if(_servant) + CurrentPtr current = createCloseCurrent(data); + try { - try - { - //业务逻辑处理 - _servant->doClose(current); - } - catch (exception &ex) - { - TLOGERROR("[TARS]ServantHandle::handleClose " << ex.what() << endl); + //业务逻辑处理 + _servant->doClose(current); + } + catch (exception &ex) + { + TLOGERROR("[TARS]ServantHandle::handleClose " << ex.what() << endl); - return; - } - catch (...) - { - TLOGERROR("[TARS]ServantHandle::handleClose unknown error" << endl); + return; + } + catch (...) + { + TLOGERROR("[TARS]ServantHandle::handleClose unknown error" << endl); - return; - } + return; } } void ServantHandle::handleTimeout(const shared_ptr &data) { - CurrentPtr current = createCurrent(data); + CurrentPtr current = createCurrent(data); - if (!current) return; + if (!current) return; //上报超时数目 - if(data->adapter()->_pReportTimeoutNum) + if (data->adapter()->_pReportTimeoutNum) data->adapter()->_pReportTimeoutNum->report(1); TLOGERROR("[ServantHandle::handleTimeout adapter '" - << data->adapter()->getName() - << "', recvtime:" << data->recvTimeStamp() << "|" - << ", timeout:" << data->adapter()->getQueueTimeout() - << ", id:" << current->getRequestId() << "]" << endl); + << data->adapter()->getName() + << "', recvtime:" << data->recvTimeStamp() << "|" + << ", timeout:" << data->adapter()->getQueueTimeout() + << ", id:" << current->getRequestId() << "]" << endl); if (current->getBindAdapter()->isTarsProtocol()) { @@ -372,15 +321,15 @@ void ServantHandle::handleTimeout(const shared_ptr void ServantHandle::handleOverload(const shared_ptr &data) { - CurrentPtr current = createCurrent(data); + CurrentPtr current = createCurrent(data); - if (!current) return; + if (!current) return; TLOGERROR("[ServantHandle::handleOverload adapter '" - << data->adapter()->getName() - << "',overload:-1,queue capacity:" - << data->adapter()->getQueueCapacity() - << ",id:" << current->getRequestId() << "]" << endl); + << data->adapter()->getName() + << "',overload:-1,queue capacity:" + << data->adapter()->getQueueCapacity() + << ",id:" << current->getRequestId() << "]" << endl); if (current->getBindAdapter()->isTarsProtocol()) { @@ -392,15 +341,14 @@ void ServantHandle::handleOverload(const shared_ptr void ServantHandle::handle(const shared_ptr &data) { - CurrentPtr current = createCurrent(data); + CurrentPtr current = createCurrent(data); - if (!current) return; + if (!current) return; if (current->getBindAdapter()->isTarsProtocol()) { handleTarsProtocol(current); - } - else + } else { handleNoTarsProtocol(current); } @@ -408,15 +356,15 @@ void ServantHandle::handle(const shared_ptr &data) reportReqTime(data, current); } -bool ServantHandle::processDye(const CurrentPtr ¤t, string& dyeingKey) +bool ServantHandle::processDye(const CurrentPtr ¤t, string &dyeingKey) { - //当前线程的线程数据 - ServantProxyThreadData *sptd = ServantProxyThreadData::getData(); + //当前线程的线程数据 + ServantProxyThreadData *sptd = ServantProxyThreadData::getData(); - if (sptd) - { - sptd->_data._dyeingKey = ""; - } + if (sptd) + { + sptd->_data._dyeingKey = ""; + } //当前请求已经被染色, 需要打印染色日志 map::const_iterator dyeingIt = current->getRequestStatus().find(ServantProxy::STATUS_DYED_KEY); @@ -434,29 +382,31 @@ bool ServantHandle::processDye(const CurrentPtr ¤t, string& dyeingKey) return true; } - //servant已经被染色, 开启染色日志 - if (_application->getServantHelper()->isDyeing()) - { - map::const_iterator dyeingKeyIt = current->getRequestStatus().find(ServantProxy::STATUS_GRID_KEY); + //servant已经被染色, 开启染色日志 + if (_application->getServantHelper()->isDyeing()) + { + map::const_iterator dyeingKeyIt = current->getRequestStatus().find( + ServantProxy::STATUS_GRID_KEY); - if (dyeingKeyIt != current->getRequestStatus().end() && - _application->getServantHelper()->isDyeingReq(dyeingKeyIt->second, current->getServantName(), current->getFuncName())) - { - TLOGTARS("[TARS] dyeing servant got a dyeing req, key:" << dyeingKeyIt->second << endl); + if (dyeingKeyIt != current->getRequestStatus().end() && + _application->getServantHelper()->isDyeingReq(dyeingKeyIt->second, current->getServantName(), + current->getFuncName())) + { + TLOGTARS("[TARS] dyeing servant got a dyeing req, key:" << dyeingKeyIt->second << endl); - dyeingKey = dyeingKeyIt->second; + dyeingKey = dyeingKeyIt->second; - return true; - } - } + return true; + } + } - return false; + return false; } bool ServantHandle::processTrace(const CurrentPtr ¤t) { //当前线程的线程数据 - ServantProxyThreadData* sptd = ServantProxyThreadData::getData(); + ServantProxyThreadData *sptd = ServantProxyThreadData::getData(); if (sptd) { @@ -479,8 +429,7 @@ bool ServantHandle::processTrace(const CurrentPtr ¤t) { sptd->_traceCall = true; return true; - } - else + } else { TLOGTARS("[TARS] servant got a trace request, but trace key is error:" << traceIt->second << endl); } @@ -491,30 +440,34 @@ bool ServantHandle::processTrace(const CurrentPtr ¤t) bool ServantHandle::processCookie(const CurrentPtr ¤t, map &cookie) { - const static string STATUS = "STATUS_"; - - std::for_each(current->getRequestStatus().begin(), current->getRequestStatus().end(),[&](const map::value_type& p){ - if(p.first.size() > STATUS.size() && TC_Port::strncasecmp(p.first.c_str(), STATUS.c_str(), STATUS.size()) == 0) { - return; - } - cookie.insert(make_pair(p.first, p.second)); - }); - - return !cookie.empty(); + const static string STATUS = "STATUS_"; + + std::for_each(current->getRequestStatus().begin(), current->getRequestStatus().end(), + [&](const map::value_type &p) + { + if (p.first.size() > STATUS.size() && + TC_Port::strncasecmp(p.first.c_str(), STATUS.c_str(), STATUS.size()) == 0) + { + return; + } + cookie.insert(make_pair(p.first, p.second)); + }); + + return !cookie.empty(); } bool ServantHandle::checkValidSetInvoke(const CurrentPtr ¤t) { - /*是否允许检查合法性*/ - if (ServerConfig::IsCheckSet == 0) - { - //不检查 - return true; - } + /*是否允许检查合法性*/ + if (_application->getServerBaseInfo().IsCheckSet == 0) + { + //不检查 + return true; + } bool isSetInvoke = IS_MSG_TYPE(current->getMessageType(), tars::TARSMESSAGETYPESETNAME); //客户端按set规则调用且服务端启用set - if (isSetInvoke && ClientConfig::SetOpen) + if (isSetInvoke && _application->getApplicationCommunicator()->getClientConfig().SetOpen) { /** * 合法性规则: @@ -523,85 +476,82 @@ bool ServantHandle::checkValidSetInvoke(const CurrentPtr ¤t) * 3 客户端set名称与服务端set属于不同名称,eg,test1.s.1 <->test2.n.2 * 4 1,2,3条件都不满足,则认为该调用不合法 */ - map::const_iterator setIt = current->getRequestStatus().find(ServantProxy::STATUS_SETNAME_VALUE); + map::const_iterator setIt = current->getRequestStatus().find( + ServantProxy::STATUS_SETNAME_VALUE); string sSetName(""); if (setIt != current->getRequestStatus().end()) { TLOGTARS("[servant got a setname request, setname key:" << setIt->second << "]" << endl); - sSetName = setIt->second; + sSetName = setIt->second; - if (ClientConfig::SetDivision == sSetName) + if (_application->getApplicationCommunicator()->getClientConfig().SetDivision == sSetName) { return true; - } - else + } else { //属于同一地区是也属于合法调用 - string setArea1 = ClientConfig::SetDivision.substr(0,ClientConfig::SetDivision.find_last_of(".")); - string setArea2 = sSetName.substr(0,sSetName.find_last_of(".")); + string setArea1 = _application->getApplicationCommunicator()->getClientConfig().SetDivision.substr(0, _application->getApplicationCommunicator()->getClientConfig().SetDivision.find_last_of(".")); + string setArea2 = sSetName.substr(0, sSetName.find_last_of(".")); if (setArea1 == setArea2) { return true; - } - else if (ClientConfig::SetDivision.substr(0,ClientConfig::SetDivision.find_first_of(".")) != - sSetName.substr(0,sSetName.find_first_of("."))) + } else if (_application->getApplicationCommunicator()->getClientConfig().SetDivision.substr(0, _application->getApplicationCommunicator()->getClientConfig().SetDivision.find_first_of(".")) != + sSetName.substr(0, sSetName.find_first_of("."))) { //属于不同的set之间调用也属于合法 return true; - } - else + } else { TLOGERROR("[ServantHandle::checkValidSetInvoke|" - << current->getIp() << "|" - << current->getMessageType() << "|" - << current->getServantName() << "|" - << current->getFuncName() << "|client:" - << ClientConfig::SetDivision << "|server:" - << sSetName << "]" << endl); + << current->getIp() << "|" + << current->getMessageType() << "|" + << current->getServantName() << "|" + << current->getFuncName() << "|client:" + << _application->getApplicationCommunicator()->getClientConfig().SetDivision << "|server:" + << sSetName << "]" << endl); current->sendResponse(TARSINVOKEBYINVALIDESET); return false; } } - } - else + } else { TLOGERROR("[ServantHandle::checkValidSetInvoke|" - << current->getIp() << "|" - << current->getMessageType() << "|" - << current->getServantName() << "|" - << current->getFuncName() << "|client:" - << ClientConfig::SetDivision << "|server:" - << sSetName << "]" << endl); + << current->getIp() << "|" + << current->getMessageType() << "|" + << current->getServantName() << "|" + << current->getFuncName() << "|client:" + << _application->getApplicationCommunicator()->getClientConfig().SetDivision << "|server:" + << sSetName << "]" << endl); current->sendResponse(TARSINVOKEBYINVALIDESET); return false; } } - //没有按set规则调用 - return true; + //没有按set规则调用 + return true; } void ServantHandle::handleTarsProtocol(const CurrentPtr ¤t) { TLOGTARS("[ServantHandle::handleTarsProtocol current:" - << current->getIp() << "|" - << current->getPort() << "|" - << current->getMessageType() << "|" - << current->getServantName() << "|" - << current->getFuncName() << "|" - << current->getRequestId() << "|" - << TC_Common::tostr(current->getRequestStatus()) << "]"<getIp() << "|" + << current->getPort() << "|" + << current->getMessageType() << "|" + << current->getServantName() << "|" + << current->getFuncName() << "|" + << current->getRequestId() << "|" + << TC_Common::tostr(current->getRequestStatus()) << "]" << endl); + + //检查set调用合法性 + if (!checkValidSetInvoke(current)) + { + return; + } //处理染色消息 - string dyeingKey = ""; + string dyeingKey; TarsDyeingSwitch dyeSwitch; if (processDye(current, dyeingKey)) { @@ -610,117 +560,109 @@ void ServantHandle::handleTarsProtocol(const CurrentPtr ¤t) processTrace(current); - //处理cookie - map cookie; - CookieOp cookieOp; - if (processCookie(current, cookie)) - { - cookieOp.setCookie(cookie); - current->setCookie(cookie); - } -// processSample(current); - - if(_servant->getName() != current->getServantName()) + //处理cookie + map cookie; + CookieOp cookieOp; + if (processCookie(current, cookie)) { - current->sendResponse(TARSSERVERNOSERVANTERR); -// #ifdef TARS_OPENTRACKING -// finishTracking(TARSSERVERNOSERVANTERR, current); -// #endif - return; + cookieOp.setCookie(cookie); + current->setCookie(cookie); } - int ret = TARSSERVERUNKNOWNERR; - string sResultDesc = ""; + string sResultDesc; - ResponsePacket response; + ResponsePacket response; try { //业务逻辑处理 - ret = _servant->dispatch(current, response.sBuffer); + if (_servant->getName() != current->getServantName()) + { + ret = _servant->doNoServant(current, response.sBuffer); + } + else + { + ret = _servant->dispatch(current, response.sBuffer); + } } - catch(TarsDecodeException &ex) + catch (TarsDecodeException &ex) { - TLOGERROR("[ServantHandle::handleTarsProtocol " << ex.what() << "]" << endl); + TLOGERROR("[ServantHandle::handleTarsProtocol decode error: " << _servant->getName() << ":" << current->getFuncName() << ", " << ex.what() << "]" << endl); ret = TARSSERVERDECODEERR; sResultDesc = ex.what(); } - catch(TarsEncodeException &ex) + catch (TarsEncodeException &ex) { - TLOGERROR("[ServantHandle::handleTarsProtocol " << ex.what() << "]" << endl); + TLOGERROR("[ServantHandle::handleTarsProtocol encode error: " << _servant->getName()<< ":" << current->getFuncName() << ", " << ex.what() << "]" << endl); ret = TARSSERVERENCODEERR; sResultDesc = ex.what(); } - catch(exception &ex) + catch (exception &ex) { - TLOGERROR("[ServantHandle::handleTarsProtocol " << ex.what() << "]" << endl); + TLOGERROR("[ServantHandle::handleTarsProtocol error: " << _servant->getName() << ":" << current->getFuncName() << ", " << ex.what() << "]" << endl); ret = TARSSERVERUNKNOWNERR; sResultDesc = ex.what(); } - catch(...) + catch (...) { - TLOGERROR("[ServantHandle::handleTarsProtocol unknown error]" << endl); + TLOGERROR("[ServantHandle::handleTarsProtocol unknown error, server:" << _servant->getName() << "]" << endl); ret = TARSSERVERUNKNOWNERR; sResultDesc = "handleTarsProtocol unknown exception error"; } - if(ret == TARSSERVERNOFUNCERR) - { - ret = _servant->doNoFunc(current); - } - + if (ret == TARSSERVERNOFUNCERR) + { + ret = _servant->doNoFunc(current, response.sBuffer); + } + //单向调用或者业务不需要同步返回 if (current->isResponse()) { - current->sendResponse(ret, response, Current::TARS_STATUS(), sResultDesc); + current->sendResponse(ret, response, {}, sResultDesc); } -#ifdef TARS_OPENTRACKING - finishTracking(ret, current); -#endif + } void ServantHandle::handleNoTarsProtocol(const TarsCurrentPtr ¤t) { TLOGTARS("[ServantHandle::handleNoTarsProtocol current:" - << current->getIp() << "|" - << current->getPort() << "|" - << current->getServantName() << "]" << endl); + << current->getIp() << "|" + << current->getPort() << "|" + << current->getServantName() << "]" << endl); -// auto sit = _servants.find(current->getServantName()); -// assert(sit != _servants.end()); - - vector buffer; + vector buffer; try { //业务逻辑处理 _servant->dispatch(current, buffer); } - catch(exception &ex) + catch (exception &ex) { - TLOGERROR("[ServantHandle::handleNoTarsProtocol " << ex.what() << "]" << endl); + TLOGERROR("[ServantHandle::handleNoTarsProtocol error: " << current->getServantName() << ", " << ex.what() << "]" << endl); } - catch(...) + catch (...) { - TLOGERROR("[ServantHandle::handleNoTarsProtocol unknown error]" << endl); + TLOGERROR("[ServantHandle::handleNoTarsProtocol unknown error: " << current->getServantName() << endl); } - if (current->isResponse() && !buffer.empty()) - { - current->sendResponse((const char *)(buffer.data()), (uint32_t)buffer.size()); - } + if (current->isResponse() && !buffer.empty()) + { + current->sendResponse((const char *) (buffer.data()), (uint32_t) buffer.size()); + } } -void ServantHandle::reportReqTime(const shared_ptr &data, const CurrentPtr ¤t) { +void ServantHandle::reportReqTime(const shared_ptr &data, const CurrentPtr ¤t) +{ current->_reqTime.setFinishTimeStamp(TNOWUS); // 上报队列等待时间 @@ -732,5 +674,4 @@ void ServantHandle::reportReqTime(const shared_ptr data->adapter()->_pReportServantHandleTime->report(current->_reqTime.servantHandleTime()); } -//////////////////////////////////////////////////////////////////////////// } diff --git a/servant/libservant/ServantHelper.cpp b/servant/libservant/ServantHelper.cpp index eea8bc9a..5642a6ed 100644 --- a/servant/libservant/ServantHelper.cpp +++ b/servant/libservant/ServantHelper.cpp @@ -18,6 +18,22 @@ namespace tars { +void ServantHelperManager::setServant(Servant * servant , const string &servantObj) +{ + ServantPtr ptr = servant; + _servant_ptr[servantObj] = ptr; +// LOG_CONSOLE_DEBUG << "setServant:" << servant << "|" << ptr->getName() << "|" << ptr.get() <create(s); diff --git a/servant/libservant/ServantProxy.cpp b/servant/libservant/ServantProxy.cpp index d114209c..77a8ea9e 100644 --- a/servant/libservant/ServantProxy.cpp +++ b/servant/libservant/ServantProxy.cpp @@ -330,6 +330,24 @@ const map & ServantProxyCallback::getResponseContext() return pCbtd->getResponseContext(); } +void ServantProxyCallback::setServantPrx(const ServantPrx &prx) +{ + _servantPrx = prx; + + _moduleName = std::make_shared(_servantPrx->_communicator->getProperty("modulename")); +} + +string ServantProxyCallback::getModuleName() +{ + auto moduleName = _moduleName; + + if(!moduleName) + { + return ServerConfig::Application + "." + ServerConfig::ServerName; + } + return *moduleName.get(); +} + /////////////////////////////////////////////////////////////////////////////////////////// int HttpServantProxyCallback::onDispatch(ReqMessagePtr msg) @@ -410,6 +428,41 @@ string ServantProxy::STATUS_SETNAME_VALUE = "STATUS_SETNAME_VALUE"; string ServantProxy::STATUS_TRACE_KEY = "STATUS_TRACE_KEY"; +ServantProxy::ServantProxy() +{ +} + +void ServantProxy::setComm(Communicator* pCommunicator, const string& name, const string& setName) +{ + _communicator = pCommunicator; + _syncTimeout = DEFAULT_SYNCTIMEOUT; + _asyncTimeout = DEFAULT_ASYNCTIMEOUT; + _id = 0; + _masterFlag = false; + _minTimeout =100; + + _proxyProtocol.requestFunc = ProxyProtocol::tarsRequest; + _proxyProtocol.responseFunc = ProxyProtocol::tarsResponse; + + //在每个公有网络线程对象中创建ObjectProxy + for (size_t i = 0; i < _communicator->getCommunicatorEpollNum(); ++i) + { + _communicator->getCommunicatorEpoll(i)->createObjectProxy(this, name, setName); + } + + //用第一个ObjectProxy返回数据 + _objectProxy = this->getObjectProxy(0); + + _endpointInfo.reset(new EndpointManagerThread(_communicator, _objectProxy->name())); + + _minTimeout = pCommunicator->getMinTimeout(); + if (_minTimeout < 1) + { + _minTimeout = 1; + } + +} + //////////////////////////////////// ServantProxy::ServantProxy(Communicator *pCommunicator, const string &name, const string &setName) : _communicator(pCommunicator), _syncTimeout(DEFAULT_SYNCTIMEOUT), _asyncTimeout(DEFAULT_ASYNCTIMEOUT), _id(0), _masterFlag(false), _minTimeout(100) @@ -417,6 +470,8 @@ ServantProxy::ServantProxy(Communicator *pCommunicator, const string &name, cons _proxyProtocol.requestFunc = ProxyProtocol::tarsRequest; _proxyProtocol.responseFunc = ProxyProtocol::tarsResponse; + _moduleName = _communicator->getProperty("modulename", TC_File::extractFileName(TC_File::getExePath())); + //在每个公有网络线程对象中创建ObjectProxy for (size_t i = 0; i < _communicator->getCommunicatorEpollNum(); ++i) { @@ -454,6 +509,11 @@ const string &ServantProxy::tars_name() const return _objectProxy->name(); } +const string &ServantProxy::tars_moduleName() const +{ + return _moduleName; +} + string ServantProxy::tars_full_name() const { string name = _objectProxy->name(); @@ -789,11 +849,17 @@ uint32_t ServantProxy::tars_gen_requestid() void ServantProxy::tars_set_push_callback(const ServantProxyCallbackPtr & cb) { + std::lock_guard lock(_mutex); _pushCallback = cb; + if(_pushCallback) + { + _pushCallback->setServantPrx(this); + } } ServantProxyCallbackPtr ServantProxy::tars_get_push_callback() { + std::lock_guard lock(_mutex); return _pushCallback; } @@ -1502,7 +1568,7 @@ void ServantProxy::http_call_async(const string &funcName, const shared_ptr *)(msg->request.sBuffer.data()) = request; - ServantProxyCallbackPtr callback = new HttpServantProxyCallback(cb); + ServantProxyCallbackPtr callback (new HttpServantProxyCallback(cb)); msg->callback = callback; @@ -1785,6 +1851,9 @@ vector ServantProxy::getEndpoint4All() return activeEndPoint; } - +void TARS_TRACE(const string &traceKey, const char *annotation, const string &client, const string &server, const char* func, int ret, const string &data, const string &ex) +{ + FDLOG(TRACE_LOG_FILENAME) << traceKey << "|" << annotation << "|" << client << "|" << server << "|" << func << "|" << TNOWMS << "|" << ret << "|" << TC_Base64::encode(data) << "|" << ex << endl; +} ////////////////////////////////////////////////////////////////////////////////////////////////// } diff --git a/servant/libservant/ServantProxyFactory.cpp b/servant/libservant/ServantProxyFactory.cpp index be912d86..797a1f5c 100644 --- a/servant/libservant/ServantProxyFactory.cpp +++ b/servant/libservant/ServantProxyFactory.cpp @@ -56,5 +56,32 @@ ServantPrx::element_type* ServantProxyFactory::getServantProxy(const string& nam return sp.get(); } +ServantProxy* ServantProxyFactory::setServantProxy(ServantProxy * proxy,const string& name,const string& setName, bool rootServant) +{ + TC_LockT lock(*this); + + string tmpObjName = name + ":" + setName; + + map::iterator it = _servantProxy.find(tmpObjName); + if(it != _servantProxy.end()) + return it->second.get(); + +// ServantPrx sp = proxy; + ServantPrx sp ( proxy); + //需要主动初始化一次 + sp->tars_initialize(rootServant); + + int syncTimeout = TC_Common::strto(_comm->getProperty("sync-invoke-timeout", "3000")); + int asyncTimeout = TC_Common::strto(_comm->getProperty("async-invoke-timeout", "5000")); + int conTimeout = TC_Common::strto(_comm->getProperty("connect-timeout", "1500")); + + sp->tars_timeout(syncTimeout); + sp->tars_async_timeout(asyncTimeout); + sp->tars_connect_timeout(conTimeout); + + _servantProxy[tmpObjName] = sp; + + return sp.get(); +} /////////////////////////////////////////////////////////////////////////////// } diff --git a/servant/libservant/StatReport.cpp b/servant/libservant/StatReport.cpp index 4655182a..905e34fb 100755 --- a/servant/libservant/StatReport.cpp +++ b/servant/libservant/StatReport.cpp @@ -37,9 +37,6 @@ StatReport::StatReport(Communicator* communicator) , _reportTimeout(5000) , _maxReportSize(MAX_REPORT_SIZE) , _terminate(false) -, _sampleRate(1) -, _maxSampleCount(500) -, _retValueNumLimit(10) { srand(time(NULL)); } @@ -69,8 +66,6 @@ void StatReport::setReportInfo(const StatFPrx& statPrx, const string& strModuleIp, const string& strSetDivision, int iReportInterval, - int iSampleRate, - unsigned int iMaxSampleCount, int iMaxReportSize, int iReportTimeout) { @@ -91,10 +86,6 @@ void StatReport::setReportInfo(const StatFPrx& statPrx, _reportTimeout = iReportTimeout < 5000 ? 5000 : iReportTimeout; - _sampleRate = (iSampleRate < 1)?1: iSampleRate; - - _maxSampleCount = iMaxSampleCount>500?500:iMaxSampleCount; - if ( iMaxReportSize < MIN_REPORT_SIZE || iMaxReportSize > MAX_REPORT_SIZE ) { _maxReportSize = MAX_REPORT_SIZE; @@ -209,19 +200,19 @@ bool StatReport::divison2SetInfo(const string& str, vector& vtSetInfo) return true; } -/* -tars.tarsstat to tarsstat -*/ -string StatReport::getServerName(string sModuleName) -{ - string::size_type pos = sModuleName.find("."); - if (pos != string::npos) - { - return sModuleName.substr(pos + 1); //+1:过滤. - } - return sModuleName; -} - +///* +//tars.tarsstat to tarsstat +//*/ +//string StatReport::getServerName(string sModuleName) +//{ +// string::size_type pos = sModuleName.find("."); +// if (pos != string::npos) +// { +// return sModuleName.substr(pos + 1); //+1:过滤. +// } +// return sModuleName; +//} +// void StatReport::report(const string& strModuleName, const string& setdivision, @@ -246,11 +237,11 @@ void StatReport::report(const string& strModuleName, { if (!_setName.empty()) { - head.masterName = _moduleName + "." + _setName + _setArea + _setID + "@" + ClientConfig::TarsVersion; + head.masterName = _moduleName + "." + _setName + _setArea + _setID + "@" + _communicator->getClientConfig().TarsVersion; } else { - head.masterName = _moduleName + "@" + ClientConfig::TarsVersion; + head.masterName = _moduleName + "@" + _communicator->getClientConfig().TarsVersion; } if (!setdivision.empty()) //被调没有启用set分组,slavename保持原样 @@ -338,7 +329,7 @@ void StatReport::report(const string& strMasterName, StatMicMsgHead head; StatMicMsgBody body; - head.masterName = trimAndLimitStr(strMasterName + "@" + ClientConfig::TarsVersion, MAX_MASTER_NAME_LEN); + head.masterName = trimAndLimitStr(strMasterName + "@" + _communicator->getClientConfig().TarsVersion, MAX_MASTER_NAME_LEN); head.masterIp = trimAndLimitStr(strMasterIp, MAX_MASTER_IP_LEN); head.slaveName = trimAndLimitStr(strSlaveName, MAX_MASTER_NAME_LEN); head.slaveIp = trimAndLimitStr(strSlaveIp, MAX_MASTER_IP_LEN); @@ -413,6 +404,7 @@ int StatReport::reportMicMsg(MapStatMicMsg& msg, bool bFromClient) msg.swap(mStatMsg); } + TLOGTARS("[StatReport::reportMicMsg get size:" << mStatMsg.size()<<"]"<< endl); for(MapStatMicMsg::iterator it = mStatMsg.begin(); it != mStatMsg.end(); it++) { @@ -425,7 +417,7 @@ int StatReport::reportMicMsg(MapStatMicMsg& msg, bool bFromClient) if(_statPrx) { TLOGTARS("[StatReport::reportMicMsg send size:" << mTemp.size()<<"]"<< endl); - _statPrx->tars_set_timeout(_reportTimeout)->async_reportMicMsg(NULL,mTemp,bFromClient, ServerConfig::Context); + _statPrx->tars_set_timeout(_reportTimeout)->async_reportMicMsg(NULL,mTemp,bFromClient, _communicator->getClientConfig().Context); } iLen = iTemLen; mTemp.clear(); @@ -447,7 +439,7 @@ int StatReport::reportMicMsg(MapStatMicMsg& msg, bool bFromClient) if(_statPrx) { TLOGTARS("[StatReport::reportMicMsg send size:" << mTemp.size()<<"]"<< endl); - _statPrx->tars_set_timeout(_reportTimeout)->async_reportMicMsg(NULL,mTemp,bFromClient, ServerConfig::Context); + _statPrx->tars_set_timeout(_reportTimeout)->async_reportMicMsg(NULL,mTemp,bFromClient, _communicator->getClientConfig().Context); } } return 0; @@ -592,7 +584,7 @@ int StatReport::reportPropMsg() if (_propertyPrx) { TLOGTARS("[StatReport::reportPropMsg send size:" << mTemp.size() << "]" << endl); - _propertyPrx->tars_set_timeout(_reportTimeout)->async_reportPropMsg(NULL, mTemp, ServerConfig::Context); + _propertyPrx->tars_set_timeout(_reportTimeout)->async_reportPropMsg(NULL, mTemp, _communicator->getClientConfig().Context); } iLen = iTemLen; mTemp.clear(); @@ -604,7 +596,7 @@ int StatReport::reportPropMsg() if (_propertyPrx) { TLOGTARS("[StatReport::reportPropMsg send size:" << mTemp.size() << "]" << endl); - _propertyPrx->tars_set_timeout(_reportTimeout)->async_reportPropMsg(NULL, mTemp, ServerConfig::Context); + _propertyPrx->tars_set_timeout(_reportTimeout)->async_reportPropMsg(NULL, mTemp, _communicator->getClientConfig().Context); } } return 0; @@ -690,7 +682,7 @@ void StatReport::run() auto communicatorEpolls = _communicator->getAllCommunicatorEpoll(); - for(auto ce : communicatorEpolls) + for(const auto& ce : communicatorEpolls) { MapStatMicMsg * pStatMsg; while(ce->popStatMsg(pStatMsg)) diff --git a/servant/makefile/tars-tools.cmake b/servant/makefile/tars-tools.cmake.in similarity index 95% rename from servant/makefile/tars-tools.cmake rename to servant/makefile/tars-tools.cmake.in index 9fad7b57..2d34cf7e 100755 --- a/servant/makefile/tars-tools.cmake +++ b/servant/makefile/tars-tools.cmake.in @@ -4,18 +4,24 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) if(WIN32) - set(TARS2CPP "c:/tars/cpp/tools/tars2cpp.exe" CACHE STRING "set tars2cpp path") - set(TARSMERGE "c:/tars/cpp/tools/tarsmerge" CACHE STRING "set tarsmerge path") - set(TARS_PATH "c:/tars/cpp") +set(TARS2CPP "@CMAKE_INSTALL_PREFIX@/tools/tars2cpp.exe" CACHE STRING "set tars2cpp path") +set(TARSMERGE "@CMAKE_INSTALL_PREFIX@/tools/tarsmerge.exe" CACHE STRING "set tarsmerge path") else() - set(TARS2CPP "/usr/local/tars/cpp/tools/tars2cpp" CACHE STRING "set tars2cpp path") - set(TARSMERGE "/usr/local/tars/cpp/tools/tarsmerge" CACHE STRING "set tarsmerge path") - set(TARS_PATH "/usr/local/tars/cpp") +set(TARS2CPP "@CMAKE_INSTALL_PREFIX@/tools/tars2cpp" CACHE STRING "set tars2cpp path") +set(TARSMERGE "@CMAKE_INSTALL_PREFIX@/tools/tarsmerge" CACHE STRING "set tarsmerge path") endif() +set(TARS_PATH "@CMAKE_INSTALL_PREFIX@") + +option(TARS_MYSQL "open mysql support" @TARS_MYSQL@) +option(TARS_SSL "open ssl support" @TARS_SSL@) +option(TARS_HTTP2 "open http2 support" @TARS_HTTP2@) set(TARS_INC "${TARS_PATH}/include") set(TARS_LIB_DIR "${TARS_PATH}/lib" ) +# set tars2cpp flag: list(APPEND TARS_TOOL_FLAG "--with-tars") +list(APPEND TARS_TOOL_FLAG "") + if(WIN32) set (LIB_TARS_SERVANT "${TARS_LIB_DIR}/tarsservant.lib") set (LIB_TARS_UTIL "${TARS_LIB_DIR}/tarsutil.lib") @@ -56,10 +62,10 @@ set(PLATFORM) IF (UNIX) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -fsigned-char") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fsigned-char -std=c++11 -Wno-deprecated -fno-strict-aliasing -Wno-overloaded-virtual") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-builtin-macro-redefined -D__FILE__='\"$(notdir $(abspath $<))\"'") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-builtin-macro-redefined") - set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -Wall -g") - set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Wall -fno-strict-aliasing") + set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_DEBUG} -Wall -g") + set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} ${CMAKE_CXX_FLAGS_RELEASE} -O2 -Wall -fno-strict-aliasing") set(PLATFORM "linux") IF (APPLE) @@ -72,7 +78,7 @@ IF (UNIX) ELSEIF (WIN32) set(PLATFORM "window") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /wd4101 /wd4244 /wd4996 /wd4091 /wd4503 /wd4819 /wd4200 /wd4800 /wd4267 /wd4251 /wd4275") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /wd4101 /wd4244 /wd4996 /wd4091 /wd4503 /wd4819 /wd4200 /wd4800 /wd4267 /wd4251 /wd4275 /bigobj") SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") @@ -83,7 +89,8 @@ ELSEIF (WIN32) SET(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} /DEBUG") SET(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /OPT:ICF /OPT:REF /DEBUG") - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj") +# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj") +# set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /bigobj") ELSE () MESSAGE(STATUS "================ ERROR: This platform is unsupported!!! ================") diff --git a/servant/protocol b/servant/protocol index 9b3921b1..a35c297d 160000 --- a/servant/protocol +++ b/servant/protocol @@ -1 +1 @@ -Subproject commit 9b3921b1036a24ed175650160f793b9b94459ea8 +Subproject commit a35c297d7fc2ece47428d661a2834a5a3521e5a0 diff --git a/servant/servant/AdminServant.h b/servant/servant/AdminServant.h index c4cc67de..442b5345 100644 --- a/servant/servant/AdminServant.h +++ b/servant/servant/AdminServant.h @@ -65,6 +65,10 @@ class AdminServant : public AdminF */ string notify(const string &command, CurrentPtr current); + /** + * 获取服务的pid + */ + tars::Int64 getPid(CurrentPtr current); }; //////////////////////////////////////////////////////////////// } diff --git a/servant/servant/Application.h b/servant/servant/Application.h index 53fcd7d4..2e0297a7 100644 --- a/servant/servant/Application.h +++ b/servant/servant/Application.h @@ -29,8 +29,8 @@ #include "servant/BaseNotify.h" #include "servant/ServantHelper.h" #include "servant/ServantHandle.h" +#include "servant/Communicator.h" #include "servant/StatReport.h" -#include "Communicator.h" #include "servant/RemoteLogger.h" #include "servant/RemoteConfig.h" #include "servant/RemoteNotify.h" @@ -74,15 +74,15 @@ namespace tars //上报错误信息 #define TARS_NOTIFY_ERROR(info) {RemoteNotify::getInstance()->notify(NOTIFYERROR, info);} -//发送心跳给node 多个adapter分别上报 -#define TARS_KEEPALIVE(adapter) {KeepAliveNodeFHelper::getInstance()->keepAlive(adapter);} - -//发送激活信息 -#define TARS_KEEPACTIVING {KeepAliveNodeFHelper::getInstance()->keepActiving();} - -//发送TARS版本给node -#define TARS_REPORTVERSION(x) {KeepAliveNodeFHelper::getInstance()->reportVersion(TARS_VERSION);} - +////发送心跳给node 多个adapter分别上报 +//#define TARS_KEEPALIVE(adapter) {KeepAliveNodeFHelper::getInstance()->keepAlive(adapter);} +// +////发送激活信息 +//#define TARS_KEEPACTIVING {KeepAliveNodeFHelper::getInstance()->keepActiving();} +// +////发送TARS版本给node +//#define TARS_REPORTVERSION(x) {KeepAliveNodeFHelper::getInstance()->reportVersion(TARS_VERSION);} +// ////////////////////////////////////////////////////////////////////// /** * 添加前置的命令处理方法 @@ -101,6 +101,50 @@ namespace tars do { addAdminCommandNormal(string(c), std::bind(&f, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); } while (0); ////////////////////////////////////////////////////////////////////// + +/** + * 服务基本信息, 不使用的ServerConfig的原因是, 如果多个Application在同一个进程中初始化ServerConfig则会有问题 + */ +struct SVT_DLL_API ServerBaseInfo +{ + std::string TarsPath; + std::string Application; //应用名称 + std::string ServerName; //服务名称,一个服务名称含一个或多个服务标识 + std::string NodeName; //服务如果部署在框架上, 则表示节点名称, 从模板中获取(framework>=3.0.17才支持), 否则为LocalIp + std::string BasePath; //应用程序路径,用于保存远程系统配置的本地目录 + std::string DataPath; //应用程序数据路径用于保存普通数据文件 + std::string LocalIp; //本机IP + std::string LogPath; //log路径 + int LogSize; //log大小(字节) + int LogNum; //log个数() + std::string LogLevel; //log日志级别 + std::string Local; //本地套接字 + std::string Node; //本机node地址 + std::string Log; //日志中心地址 + std::string Config; //配置中心地址 + std::string Notify; //信息通知中心 + std::string ConfigFile; //框架配置文件路径 + bool CloseCout; + int ReportFlow; //是否服务端上报所有接口stat流量 0不上报 1上报(用于非tars协议服务流量统计) + int IsCheckSet; //是否对按照set规则调用进行合法性检查 0,不检查,1检查 + int OpenCoroutine; //是否启用协程处理方式(0~3) + size_t CoroutineMemSize; //协程占用内存空间的最大大小 + uint32_t CoroutineStackSize; //每个协程的栈大小(默认128k) + int NetThread; //servernet thread + bool ManualListen; //是否启用手工端口监听 + int BackPacketLimit; //回包积压检查 + int BackPacketMin; //回包速度检查 + int BakFlag = 0; + int BakType = 0; + + std::string CA; + std::string Cert; + std::string Key; + bool VerifyClient; + std::string Ciphers; + map Context; //框架内部用, 传递节点名称(以域名形式部署时) +}; + /** * 服务基本信息 */ @@ -109,6 +153,7 @@ struct SVT_DLL_API ServerConfig static std::string TarsPath; static std::string Application; //应用名称 static std::string ServerName; //服务名称,一个服务名称含一个或多个服务标识 + static std::string NodeName; //服务如果部署在框架上, 则表示节点名称, 从模板中获取(framework>=3.0.17才支持), 否则为LocalIp static std::string BasePath; //应用程序路径,用于保存远程系统配置的本地目录 static std::string DataPath; //应用程序数据路径用于保存普通数据文件 static std::string LocalIp; //本机IP @@ -125,24 +170,32 @@ struct SVT_DLL_API ServerConfig static bool CloseCout; static int ReportFlow; //是否服务端上报所有接口stat流量 0不上报 1上报(用于非tars协议服务流量统计) static int IsCheckSet; //是否对按照set规则调用进行合法性检查 0,不检查,1检查 - static int OpenCoroutine; //是否启用协程处理方式(0~3) + static int OpenCoroutine; //是否启用协程处理方式(0~3) static size_t CoroutineMemSize; //协程占用内存空间的最大大小 static uint32_t CoroutineStackSize; //每个协程的栈大小(默认128k) static int NetThread; //servernet thread static bool ManualListen; //是否启用手工端口监听 static int BackPacketLimit; //回包积压检查 static int BackPacketMin; //回包速度检查 - - static std::string CA; - static std::string Cert; - static std::string Key; - static bool VerifyClient; - static std::string Ciphers; + static int BakFlag; //是否启用是备机: 0: 非备机, 1: 备机 + static int BakType; //主备切换类型: 0 不需要主备切换,1:自动主从切换, 2:自动切换但是不屏蔽主控路由 + static std::string CA; //ssl ca + static std::string Cert; //ssl 证书 + static std::string Key; //ssl 私钥 + static bool VerifyClient; //是否验证客户端 + static std::string Ciphers; //过滤的加密算法cd static map Context; //框架内部用, 传递节点名称(以域名形式部署时) + + /** + * 转换成ServerBaseInfo, 在initializeServer之后会自动调用, 复制给Application中的_serverBaseInfo + * @return + */ + static ServerBaseInfo toServerBaseInfo(); }; class PropertyReport; +class KeepAliveNodeFHelper; ////////////////////////////////////////////////////////////////////// /** @@ -205,6 +258,18 @@ class Application: public BaseNotify */ static CommunicatorPtr& getCommunicator(); + /** + * application自己的通信器, 当一个进程中内嵌多个Application时出现, 否则等于getCommunicator() + * @return + */ + CommunicatorPtr& getApplicationCommunicator(); + + /** + * application自己的获取远程系统配置 + * @return + */ + shared_ptr getRemoteConfig() { return _remoteConfig; } + /** * 获取服务Server对象 * @@ -301,6 +366,18 @@ class Application: public BaseNotify */ TC_EpollServer::BindAdapterPtr getBindAdapter(const string &obj); + /** + * 获取服务基本信息 + * @return + */ + const ServerBaseInfo &getServerBaseInfo() const { return _serverBaseInfo; } + + /** + * 是否已经结束了 + * @return + */ + bool isTerminate(); + protected: /** * 初始化, 只会进程调用一次 @@ -321,7 +398,19 @@ class Application: public BaseNotify * 初始化ServerConfig之后, 给app调整自定义配置值的机会 */ virtual void onServerConfig(){}; - + + /** + * 成为主机(企业版功能) + * 一主多备模式下, 切换成主机模式下回调给业务 + */ + virtual void onMaster() {}; + + /** + * 成为备机(企业版功能) + * 一主多备模式下, 切换成备机模式下回调给业务 + */ + virtual void onSlave() {}; + /** * 处理加载配置的命令 * 处理完成后继续通知Servant @@ -520,10 +609,21 @@ class Application: public BaseNotify */ TC_EpollServer::BindAdapter::EOrder parseOrder(const string &s); + /** + * 初始化adapter + */ + void initializeAdapter(); + + /** + * 根据配置创建adapter + * @return + */ + vector createAdapter(); + /** * bind server adapter */ - void bindAdapter(vector &adapters); + void bindAdapters(); /** * set adapter @@ -553,7 +653,21 @@ class Application: public BaseNotify */ string setDivision(void); + friend class ServantHandle; + +private: + /** + * 检查主备状态(企业版框架才支持) + */ + void checkMasterSlave(int timeout); + protected: + + /** + * server base info + */ + ServerBaseInfo _serverBaseInfo; + /** * config */ @@ -569,6 +683,12 @@ class Application: public BaseNotify */ static CommunicatorPtr _communicator; + /** + * communicator 每个application都自带一个, 如果_communicator已经存在, 则创建新的, 否则和_communicatory一样 + * 解决一个进程中内嵌多个Application时, 共享通信器的问题! + */ + CommunicatorPtr _applicationCommunicator; + /** * accept */ @@ -592,9 +712,15 @@ class Application: public BaseNotify size_t _ctrlCId = -1; size_t _termId = -1; - PropertyReport * _pReportQueue; - PropertyReport * _pReportConRate; - PropertyReport * _pReportTimeoutNum; + shared_ptr _keepAliveNodeFHelper; + + shared_ptr _remoteConfig; + + TC_ThreadLock _masterSlaveLock; + bool _terminateCheckMasterSlave = false; + std::thread *_masterSlaveCheckThread = nullptr; //主备模式检查线程(企业版框架功能) + + }; //////////////////////////////////////////////////////////////////// } diff --git a/servant/servant/Communicator.h b/servant/servant/Communicator.h index 7ccbc255..0d184238 100644 --- a/servant/servant/Communicator.h +++ b/servant/servant/Communicator.h @@ -23,12 +23,10 @@ #include "servant/Global.h" #include "servant/ServantProxy.h" #include "servant/ServantProxyFactory.h" -//#include "servant/ObjectProxyFactory.h" #include "servant/AsyncProcThread.h" -// #include "servant/CommunicatorEpoll.h" #include "servant/StatReport.h" #include "servant/RemoteLogger.h" - +#include "servant/QueryF.h" #include "util/tc_openssl.h" // #ifdef TARS_OPENTRACKING @@ -117,38 +115,6 @@ class CommunicatorEpoll; class TC_OpenSSL; //////////////////////////////////////////////////////////////////////// -/** - * 客户端配置 - */ -struct ClientConfig -{ - /** - * 客户端IP地址 - */ - static string LocalIp; - /** - * 客户端模块名称 - */ - static string ModuleName; - /** - * 客户端所有的IP地址 - */ - static set SetLocalIp; - /** - *客户端是否打开set分组 - */ - static bool SetOpen; - /** - *客户端set分组 - */ - static string SetDivision; - - /** - * 客户端的版本号 - */ - static string TarsVersion; -}; - //////////////////////////////////////////////////////////////////////// /** * 通信器,用于创建和维护客户端proxy @@ -156,8 +122,52 @@ struct ClientConfig class SVT_DLL_API Communicator : public TC_HandleBase, public TC_ThreadRecMutex { public: - - typedef std::function custom_callback; + /** + * 客户端配置 + */ + struct ClientConfig + { + /** + * 客户端IP地址 + */ + string LocalIp = "127.0.0.1"; + + /** + * 部署的节点名称, 如果独立客户端则为LocalIp; + */ + string NodeName; + + /** + * 访问框架服务时, 传入的context, 目前: ["node_name"] = NodeName + */ + map Context; + + /** + * 客户端模块名称 + */ + string ModuleName; + + /** + * 客户端所有的IP地址 + */ + set SetLocalIp; + + /** + *客户端是否打开set分组 + */ + bool SetOpen = false; + /** + *客户端set分组 + */ + string SetDivision; + + /** + * 客户端的版本号 + */ + string TarsVersion; + }; + + typedef std::function custom_callback; /** * 构造函数 @@ -206,7 +216,9 @@ class SVT_DLL_API Communicator : public TC_HandleBase, public TC_ThreadRecMutex ServantProxy *pServantProxy = getServantProxy(objectName, setName, true); proxy = (typename T::element_type *)(pServantProxy); } - + + ServantProxy * setServantProxy( ServantProxy * proxy, const string& objectName,const string& setName, bool rootServant); + /** * 获取公有网络线程个数 * @return @@ -342,6 +354,18 @@ class SVT_DLL_API Communicator : public TC_HandleBase, public TC_ThreadRecMutex */ bool isTerminating(); + /** + * 如果没有配置locator, 则返回null + * @return + */ + const QueryFPrx &getLocatorPrx() { return _queryFPrx; } + + /** + * 获取set等信息 + * @return + */ + const ClientConfig &getClientConfig() const { return _clientConfig; } + protected: /** * 初始化 @@ -425,7 +449,7 @@ class SVT_DLL_API Communicator : public TC_HandleBase, public TC_ThreadRecMutex * * @param func */ - void forEachSchedCommunicatorEpoll(std::function &)> func); + void forEachSchedCommunicatorEpoll(const std::function &)>& func); /** * 创建一个协程内的网络通信器 @@ -442,6 +466,8 @@ class SVT_DLL_API Communicator : public TC_HandleBase, public TC_ThreadRecMutex /** * 框架内部需要直接访问通信器的类 */ + friend class Application; + friend class AdapterProxy; friend class ServantProxy; @@ -479,7 +505,12 @@ class SVT_DLL_API Communicator : public TC_HandleBase, public TC_ThreadRecMutex */ map> _objInfo; - /** + /* + * 主控的路由代理 + */ + QueryFPrx _queryFPrx; + + /** * ServantProxy代码的工厂类 */ ServantProxyFactory* _servantProxyFactory; @@ -487,17 +518,18 @@ class SVT_DLL_API Communicator : public TC_HandleBase, public TC_ThreadRecMutex /* * 公有网络线程 */ - vector> _communicatorEpoll;//[MAX_CLIENT_THREAD_NUM]; + vector> _communicatorEpoll; //[MAX_CLIENT_THREAD_NUM]; /** * 私有网络线程, 会动态变化 */ - unordered_map> _schedCommunicatorEpoll; +// unordered_map> _schedCommunicatorEpoll; + vector> _schedCommunicatorEpoll; //MAX_CLIENT_NOTIFYEVENT_NUM - /** - * 操作通信器的锁 - */ - TC_SpinLock _schedMutex; +// /** +// * 操作通信器的锁 +// */ +// TC_SpinLock _schedMutex; /** * 锁 @@ -568,7 +600,11 @@ class SVT_DLL_API Communicator : public TC_HandleBase, public TC_ThreadRecMutex * 注册事件 */ size_t _sigId = -1; - + + /** + * 客户端配置 + */ + ClientConfig _clientConfig; // #ifdef TARS_OPENTRACKING // public: // struct TraceManager:public TC_HandleBase{ diff --git a/servant/servant/Current.h b/servant/servant/Current.h index 86f6683d..709fd756 100644 --- a/servant/servant/Current.h +++ b/servant/servant/Current.h @@ -37,13 +37,13 @@ class Current : public TC_HandleBase public: typedef std::map TARS_STATUS; - typedef std::vector TARS_BUFFER; +// typedef std::vector TARS_BUFFER; /** * 构造函数 * @param pServantHandle */ - Current(ServantHandle *pServantHandle); + Current(const shared_ptr &pServantHandle); /** * 析构 @@ -121,6 +121,12 @@ class Current : public TC_HandleBase */ ServantHandle* getServantHandle(); + /** + * 当前此服务端的名称: app.server, 给调用链使用 + * @return + */ + string getModuleName(); + /** * 获取来源的Adapter * @return TC_EpollServer::BindAdapter* @@ -187,10 +193,16 @@ class Current : public TC_HandleBase */ struct timeval getRecvTime() const; - /** - * 设置是否上报状态报告 - */ - void setReportStat(bool bReport); + /** + * 数据接收到时间(微秒) + * @return + */ + int64_t recvTimeStampUs() const; + +// /** +// * 设置是否上报状态报告 +// */ +// void setReportStat(bool bReport); /** * 获取RequestPacket @@ -223,28 +235,28 @@ class Current : public TC_HandleBase void sendResponse(int iRet, tup::UniAttribute& attr); /** - * tars协议的发送响应数据(仅TARS协议有效) + * tars协议的发送响应数据(仅TARS协议有效), 给底层包iRet和sBuffer复制, 序列化后发送, 生成的代码中调用 * @param iRet * @param buff */ void sendResponse(int iRet, const vector &buff); /** - * tars协议的发送响应数据(仅TARS协议有效) + * tars协议的发送响应数据(仅TARS协议有效), 给底层包iRet和sBuffer复制, 序列化后发送, 生成的代码中调用 * @param iRet * @param buff */ void sendResponse(int iRet, const string &buff); /** - * 普通协议的发送响应数据(非TARS协议有效) + * 普通协议的发送响应数据(非TARS协议有效), 直接发送buff裸数据 * @param buff * @param len */ void sendResponse(const char* buff, uint32_t len); /** - * + * tars协议使用 * @param iRet * @param response * @param status @@ -254,11 +266,13 @@ class Current : public TC_HandleBase void sendResponse(int iRet, ResponsePacket &response, const map& status, const string& sResultDesc); /** - * 针对Push消息的应答数据 + * push callback机制中, 针对Push消息的应答数据(自动生成的代码中使用, 一般业务不主动使用该函数) * @param buff * @param len */ void sendPushResponse(int iRet, const string &funcName, TarsOutputStream& oss, const map &context = tars::Current::TARS_STATUS()); + void sendPushResponse(int iRet, const string &funcName , vector &buff ); + /** * 设置调用链追踪信息,服务端主动回包时用 * @param traceCall @@ -270,10 +284,11 @@ class Current : public TC_HandleBase * 是否需要追踪调用链 */ bool isTraced() const; + /** * 调用链追踪Key */ - string getTraceKey() const; + const string &getTraceKey() const; /** * 服务器端连接是否还存在 @@ -304,10 +319,10 @@ class Current : public TC_HandleBase */ void initialize(const vector &sRecvBuffer); - /** - * 服务端上报状态,针对单向调用及WUP调用(仅对TARS协议有效) - */ - void reportToStat(const string & sObj); +// /** +// * 服务端上报状态,针对单向调用及TUP调用 +// */ +// void reportToStat(const string & sObj); /** * 设置cookie @@ -334,7 +349,7 @@ class Current : public TC_HandleBase /** * 操作类指针 */ - ServantHandle* _servantHandle; + shared_ptr _servantHandle; /** * 接收到的数据 @@ -356,10 +371,10 @@ class Current : public TC_HandleBase */ int _ret; - /** - * 是否上报stat - */ - bool _reportStat; +// /** +// * 是否上报stat +// */ +// bool _reportStat; /** * 设置额外返回的内容 diff --git a/servant/servant/EndpointInfo.h b/servant/servant/EndpointInfo.h index 0603bc04..6da493bb 100755 --- a/servant/servant/EndpointInfo.h +++ b/servant/servant/EndpointInfo.h @@ -17,11 +17,9 @@ #ifndef __TARS_ENDPOINT_INFO_H_ #define __TARS_ENDPOINT_INFO_H_ -//#include "servant/Global.h" #include "util/tc_socket.h" #include "util/tc_clientsocket.h" #include "servant/EndpointF.h" -//#include "AuthF.h" #if TARGET_PLATFORM_WINDOWS #include @@ -57,6 +55,53 @@ class EndpointInfo */ EndpointInfo(const EndpointF &ep); + /** + * 转换 + * @param ep + * @return + */ + static TC_Endpoint toEndpointF(const EndpointF &ep); + + /** + * 转换 + * @param ep + * @return + */ + static EndpointF toEndpointF(const TC_Endpoint &ep, const string &nodeName); + + /** + * 转换数据结构 + * 如果是0.0.0.0 则换成本机实际ipv4的所有地址(多网卡), 注意去掉了127.0.0.1 + * 如果是::1, 则换成本机实际ipv6的所有地址(多网卡), 注意去掉了::1 + * 如果是*, 则换成本机所有的ipv4/ipv6的所有地址(多网卡), 注意去掉了127.0.0.1 和 ::1 + * @param ep + * @param nodeName + * @return + */ + static vector toEndpointFs(const TC_Endpoint &ep, const string &nodeName); + + /** + * 转换成字符串, 方便输出 + * @param eps + * @param complete: 是否完整转换 + * @return complete: false->ip1:port,ip2:port2,... complete: true -> tcp -h .. -p ..:tcp -h .. -p .. + */ + static string vectorEndpointFToStr(const vector &eps, bool complete = true); + + /** + * 字符串转换成vector + * @param str, tcp -h .. -p ..:tcp -h .. -p .. + * @param nodeName + * @return + */ + static vector strToVectorEndpointF(const string &str, const string &nodeName); + + /** + * 按照节点名称归并 + * @return <节点名称, [地址]> + */ + static map> toNodeEndpointF(const vector &eps); + /** * get endpoint * @return diff --git a/servant/servant/EndpointManager.h b/servant/servant/EndpointManager.h index b74f08c1..9e6bc29d 100644 --- a/servant/servant/EndpointManager.h +++ b/servant/servant/EndpointManager.h @@ -51,7 +51,7 @@ enum EndpointWeightType /* * 路由请求与回调的实现类 */ -class QueryEpBase : public QueryFPrxCallback +class QueryEpBase : public QueryFPrxCallback ,public enable_shared_from_this { public: /* @@ -132,7 +132,7 @@ class QueryEpBase : public QueryFPrxCallback /* * 设置主控的代理 */ - int setLocatorPrx(QueryFPrx prx); + int setLocatorPrx(const QueryFPrx& prx); /* * 是否直连后端 @@ -146,6 +146,10 @@ class QueryEpBase : public QueryFPrxCallback */ void refreshReg(GetEndpointType type,const string & sName); + /** + * 从cache中加载ip list + */ + void loadFromCache(); private: /* @@ -155,11 +159,6 @@ class QueryEpBase : public QueryFPrxCallback */ void setObjName(const string & sObjName); -// /* -// * 解析endpoint -// */ -// vector sepEndpoint(const string& sEndpoints); - /* * 从sEndpoints提取ip列表信息 */ diff --git a/servant/servant/Global.h b/servant/servant/Global.h index 2e5fe0a6..4d483f2b 100755 --- a/servant/servant/Global.h +++ b/servant/servant/Global.h @@ -65,14 +65,29 @@ class RemoteNotify; typedef TC_AutoPtr CommunicatorPtr; typedef TC_AutoPtr ServantPrx; +typedef TC_AutoPtr StatFPrx; + +#ifdef TARS_STD_SHARED_PTR + +typedef std::shared_ptr ServantProxyCallbackPtr; +typedef std::shared_ptr ObjectPrx; +typedef std::shared_ptr CurrentPtr; +typedef std::shared_ptr StatReportPtr; +typedef std::shared_ptr FDReactorPtr; +typedef std::shared_ptr AsyncProcThreadPtr; + +#else + typedef TC_AutoPtr ServantProxyCallbackPtr; typedef TC_AutoPtr ObjectPrx; typedef TC_AutoPtr CurrentPtr; -typedef TC_AutoPtr StatFPrx; typedef TC_AutoPtr StatReportPtr; typedef TC_AutoPtr FDReactorPtr; typedef TC_AutoPtr AsyncProcThreadPtr; +#endif + + typedef CurrentPtr TarsCurrentPtr; typedef RemoteConfig TarsRemoteConfig; typedef RemoteNotify TarsRemoteNotify; diff --git a/servant/servant/KeepAliveNodeF.h b/servant/servant/KeepAliveNodeF.h index b4733a1e..26faaace 100644 --- a/servant/servant/KeepAliveNodeF.h +++ b/servant/servant/KeepAliveNodeF.h @@ -19,7 +19,7 @@ #include "servant/NodeF.h" #include "servant/Global.h" -#include "util/tc_singleton.h" +//#include "util/tc_singleton.h" namespace tars { @@ -28,7 +28,7 @@ namespace tars * 给node发送心跳 * 调用keepAlive异步发送心跳给node */ -class SVT_DLL_API KeepAliveNodeFHelper : public TC_Singleton,public TC_ThreadMutex +class SVT_DLL_API KeepAliveNodeFHelper : public TC_ThreadMutex { public: diff --git a/servant/servant/PropertyReport.h b/servant/servant/PropertyReport.h index fbcd3004..2d7b5a7e 100755 --- a/servant/servant/PropertyReport.h +++ b/servant/servant/PropertyReport.h @@ -82,12 +82,12 @@ class PropertyReport : public TC_HandleBase protected: void clear() { _sum = 0; _count = 0; } private: - int _sum; + int64_t _sum; int _count; }; /** - * 分布 + * 分布(不建议再使用了) */ class distr { @@ -98,10 +98,11 @@ class PropertyReport : public TC_HandleBase void set(int o); string get(); protected: - void clear() { _result.clear();} + void clear() { _result.clear(); _max = 0;} private: vector _range; vector _result; + int _max = 0; }; /** diff --git a/servant/servant/RemoteConfig.h b/servant/servant/RemoteConfig.h index dc5a32d7..a72f8efd 100644 --- a/servant/servant/RemoteConfig.h +++ b/servant/servant/RemoteConfig.h @@ -43,7 +43,10 @@ namespace tars * */ -class SVT_DLL_API RemoteConfig : public TC_Singleton +class ConfigProxy; +typedef tars::TC_AutoPtr ConfigPrx; + +class SVT_DLL_API RemoteConfig //: public TC_Singleton { public: /** @@ -57,7 +60,7 @@ class SVT_DLL_API RemoteConfig : public TC_Singleton * * @return int */ - int setConfigInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string& basePath,const string& setdivision="",int maxBakNum = 5); + int setConfigInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string& basePath, const string& setdivision="",int maxBakNum = 5); /** * 读取ConfigServer上配置文件到本地,并备份原文件 @@ -105,11 +108,6 @@ class SVT_DLL_API RemoteConfig : public TC_Singleton */ inline void localRename(const string& oldFile, const string& newFile); - /** - * 获取hostname, 给k8s版本使用 - */ - string getHostName(); - protected: /** diff --git a/servant/servant/RemoteLogger.h b/servant/servant/RemoteLogger.h index e72920d1..fe3fc413 100755 --- a/servant/servant/RemoteLogger.h +++ b/servant/servant/RemoteLogger.h @@ -56,6 +56,8 @@ namespace tars 8 RemoteTimeLogger会在RemoteTimeWriteT对象中, 异步写入到远程 9 从而本地文件写和远程写不在一个线程中. *****************************************************************************/ +//class LogProxy; +//typedef tars::TC_AutoPtr LogPrx; /////////////////////////////////////////////////////////////////////////////// @@ -67,14 +69,12 @@ class RollWriteT void operator()(ostream &of, const deque > &ds); - void setDyeingLogInfo(const string &sApp, const string &sServer, const string & sLogPath, int iMaxSize, int iMaxNum, const LogPrx &logPrx, const string & sLogObj); + void setDyeingLogInfo(const string &sApp, const string &sServer, const string & sLogPath, int iMaxSize, int iMaxNum, const LogPrx &logPrx); protected: TC_RollLogger *_dyeingRollLogger; -// static int _dyeingThread; - string _app; string _server; string _logPath; @@ -86,6 +86,7 @@ class RollWriteT */ LogPrx _logPrx; + map _context; }; @@ -290,7 +291,7 @@ class RemoteTimeWriteT /** * 同步到远程 */ - void sync2remote(const vector &buffer); + void sync2remote(const LogInfo &stInfo, const vector &buffer); /** * 染色日志同步到远程 @@ -999,23 +1000,6 @@ class TarsDyeingSwitch #define FDLOG_DEBUG(x) FDLOG(x) << FILE_FUNC_LINE << "|" #endif -/////////////////////////////////////////// -/** - * 调用链追踪 - */ -#define TRACE_ANNOTATION_TS "ts" -#define TRACE_ANNOTATION_TE "te" -#define TRACE_ANNOTATION_CS "cs" -#define TRACE_ANNOTATION_CR "cr" -#define TRACE_ANNOTATION_SR "sr" -#define TRACE_ANNOTATION_SS "ss" - -#define TRACE_LOG_FILENAME "_t_trace_" -// traceKey: traceType-TraceID|SpanID|ParentSpanID -#define TARS_TRACE(traceKey, annotation, client, server, func, ret, data, ex) \ - { \ - FDLOG(TRACE_LOG_FILENAME) << traceKey << "|" << annotation << "|" << client << "|" << server << "|" << func << "|" << TNOWMS << "|" << ret << "|" << TC_Base64::encode(data) << "|" << ex << endl; \ - } ////////////////////////////////////////////// /** diff --git a/servant/servant/RemoteNotify.h b/servant/servant/RemoteNotify.h index 4b86187c..809bc9d6 100644 --- a/servant/servant/RemoteNotify.h +++ b/servant/servant/RemoteNotify.h @@ -43,7 +43,7 @@ class SVT_DLL_API RemoteNotify : public TC_Singleton * * @return int */ - int setNotifyInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string &sSetName, const string &nodeName); + int setNotifyInfo(const CommunicatorPtr &comm, const string &obj, const string & app, const string &serverName, const string &sSetName); /** * 通知, 一定是异步上报的 @@ -89,11 +89,6 @@ class SVT_DLL_API RemoteNotify : public TC_Singleton *set 名字 */ string _setName; - - /* - *节点 - */ - string _nodeName; }; } diff --git a/servant/servant/Servant.h b/servant/servant/Servant.h index 1c4367a0..891c3b40 100644 --- a/servant/servant/Servant.h +++ b/servant/servant/Servant.h @@ -29,6 +29,14 @@ namespace tars { class Application; +class ServantHandle; +class BufferWrapper +{ +public: + vector buffer; +}; + +typedef std::shared_ptr BufferWrapperPtr; //////////////////////////////////////////////////////////////////// /** @@ -63,7 +71,7 @@ class Servant : public BaseNotify * 设置所属的Handle * @param handle */ - void setHandle(TC_EpollServer::Handle* handle); + void setHandle(const shared_ptr &handle); /** * 设置全局的应用 @@ -77,11 +85,17 @@ class Servant : public BaseNotify */ Application* getApplication() const; + /** + * 获取服务端的名称: app.server + * @return + */ + string getModuleName(); + /** * 获取所属的Handle * @return HandlePtr& */ - TC_EpollServer::Handle* getHandle(); + shared_ptr getHandle(); /** * 初始化 @@ -94,6 +108,8 @@ class Servant : public BaseNotify */ virtual void destroy() = 0; + void setModePython( bool forPython); + bool isPython() ; public: /** * 分发收到的请求 @@ -112,6 +128,8 @@ class Servant : public BaseNotify * @return int */ virtual int onDispatch(CurrentPtr current, vector &buffer) { return -1; } + + virtual int onDispatch(CurrentPtr current, BufferWrapper * bufferWrapper) { return -1; } public: /** @@ -166,12 +184,21 @@ class Servant : public BaseNotify */ virtual int doClose(CurrentPtr current){ return -1; } + /** + * tars协议, 没有servant时候会调用 + * @param current + * @param buffer: 输出的buffer数据 + * @return 成功请返回0, 异常可以返回: [TARSSERVERSUCCESS~TARSSERVERUNKNOWNERR] + */ + virtual int doNoServant(CurrentPtr current, vector &buffer) {return tars::TARSSERVERNOSERVANTERR;} + /** * tars协议, 没有对应函数时会调用 * @param current - * @return + * @param buffer: 输出的buffer数据 + * @return 成功请返回0, 异常可以返回: [TARSSERVERSUCCESS~TARSSERVERUNKNOWNERR] */ - virtual int doNoFunc(CurrentPtr current) {return tars::TARSSERVERNOFUNCERR;} + virtual int doNoFunc(CurrentPtr current, vector &buffer) {return tars::TARSSERVERNOFUNCERR;} /** * 获得响应的数据队列 @@ -193,7 +220,7 @@ class Servant : public BaseNotify /** * 所属的Handle */ - TC_EpollServer::Handle* _handle; + std::weak_ptr _handle; /** * 异步响应队列, 每个Servant一个队列, 这个用于在ServantImp中, 再异步发请求给其他服务 @@ -201,6 +228,8 @@ class Servant : public BaseNotify * 缺点就是Servant::onDispatch, 通知ServantImp时, 需要把所有线程都唤醒 */ TC_CasQueue _asyncResponseQueue; + + bool _modePython = false; }; typedef TC_AutoPtr ServantPtr; @@ -216,36 +245,36 @@ class ServantCallback : public ServantProxyCallback public: /** * 构造函数,type用来区分同一链路上的多种cb对象类型 - * @param type - * @param servant - * @param current + * @param type + * @param servant + * @param current */ ServantCallback(const string& type, const ServantPtr& servant, const CurrentPtr& current); /** - * callback的响应接口 - * @param msg - * @return int + * callback的响应接口 + * @param msg + * @return int */ virtual int onDispatch(ReqMessagePtr msg); /** * 连接关闭 - * @param msg - * @return int - */ + * @param msg + * @return int + */ virtual void onClose() { } /** * 获得生成时所属的servant - * @return const ServantPtr& + * @return const ServantPtr& */ const ServantPtr& getServant(); /** * 获得网络上下文 - * @return const CurrentPtr& + * @return const CurrentPtr& */ const CurrentPtr& getCurrent(); @@ -261,7 +290,7 @@ class ServantCallback : public ServantProxyCallback ////////////////////////////////////////////////////////////////////// //线程私有数据 -class CallbackThreadData //: public TC_ThreadPool::ThreadData +class CallbackThreadData { public: static thread_local shared_ptr g_sp; diff --git a/servant/servant/ServantHandle.h b/servant/servant/ServantHandle.h index 9a5e8c95..18b48aa3 100644 --- a/servant/servant/ServantHandle.h +++ b/servant/servant/ServantHandle.h @@ -39,7 +39,7 @@ class Application; /** * 处理网络请求线程 */ -class ServantHandle : public TC_EpollServer::Handle +class ServantHandle : public TC_EpollServer::Handle, public enable_shared_from_this { public: /** @@ -66,6 +66,12 @@ class ServantHandle : public TC_EpollServer::Handle */ Application *getApplication() { return _application; } + /** + * 获取服务端的名称: app.server + * @return + */ + string getModuleName(); + /** * 获取实际的servant * @return diff --git a/servant/servant/ServantHelper.h b/servant/servant/ServantHelper.h index cd12b235..a71b29c7 100644 --- a/servant/servant/ServantHelper.h +++ b/servant/servant/ServantHelper.h @@ -64,6 +64,13 @@ struct ServantCreationWithParams : public ServantHelperCreation ////////////////////////////////////////////////////////////////////////////// // +using function_servant_create = std::function< Servant * (void) >; + +struct ServantCreateHelper +{ + function_servant_create creator; + Application *application = nullptr; +}; /** * Servant管理 */ @@ -189,7 +196,9 @@ class SVT_DLL_API ServantHelperManager// : public TC_Singleton _servant_adapter; + map _servant_ptr; + + map _servant_creator_ptr; protected: /** diff --git a/servant/servant/ServantProxy.h b/servant/servant/ServantProxy.h index 89dd00ae..90b8fba4 100644 --- a/servant/servant/ServantProxy.h +++ b/servant/servant/ServantProxy.h @@ -28,6 +28,7 @@ #include "servant/AppProtocol.h" #include "servant/Current.h" #include "servant/EndpointInfo.h" + #include #include #include @@ -37,6 +38,22 @@ namespace tars class CommunicatorEpoll; class EndpointInfo; + +/////////////////////////////////////////// +/** + * 调用链追踪 + */ +#define TRACE_ANNOTATION_TS "ts" +#define TRACE_ANNOTATION_TE "te" +#define TRACE_ANNOTATION_CS "cs" +#define TRACE_ANNOTATION_CR "cr" +#define TRACE_ANNOTATION_SR "sr" +#define TRACE_ANNOTATION_SS "ss" + +#define TRACE_LOG_FILENAME "_t_trace_" +// traceKey: traceType-TraceID|SpanID|ParentSpanID +void TARS_TRACE(const string &traceKey, const char *annotation, const string &client, const string &server, const char* func, int ret, const string &data, const string &ex); + ///////////////////////////////////////////////////////////////////////// //seq 管理的类 @@ -600,7 +617,7 @@ class ServantProxyCallback : virtual public TC_HandleBase * 设置发起调用的servant * @param prx */ - void setServantPrx(const ServantPrx &prx) { _servantPrx = prx; } + void setServantPrx(const ServantPrx &prx); /** * 获取类型 @@ -673,6 +690,12 @@ class ServantProxyCallback : virtual public TC_HandleBase virtual void onConnect(const TC_Endpoint& ep, int fd) {} + /** + * get module name + * @return + */ + string getModuleName(); + friend class AdapterProxy; protected: @@ -696,6 +719,11 @@ class ServantProxyCallback : virtual public TC_HandleBase * servant prx */ ServantPrx _servantPrx; + + /** + * moduleName for trace + */ + shared_ptr _moduleName; }; /////////////////////////////////////////////////////////////////////////////////////////////// // for http @@ -814,12 +842,20 @@ class ServantProxy : public TC_HandleBase, public TC_ThreadMutex PROXY_HTTP, //支持http代理 }; + ServantProxy() ; + /** * 构造函数 * @param op */ ServantProxy(Communicator * pCommunicator, const string& name,const string& setName); + /** + * 主动设置通信器参数 + * @param op + */ + void setComm(Communicator* pCommunicator, const string& name, const string& setName); + /** * 析构函数 */ @@ -951,6 +987,12 @@ class ServantProxy : public TC_HandleBase, public TC_ThreadMutex */ const string &tars_name() const; + /** + * 当前客户端的moduleName + * @return + */ + const string &tars_moduleName() const; + /** * set name * @return @@ -1430,6 +1472,10 @@ class ServantProxy : public TC_HandleBase, public TC_ThreadMutex */ vector _socketOpts; + /** + * 对应通信内部的moduleName + */ + string _moduleName; }; } #endif diff --git a/servant/servant/ServantProxyFactory.h b/servant/servant/ServantProxyFactory.h index fe8dfe09..5f01daef 100644 --- a/servant/servant/ServantProxyFactory.h +++ b/servant/servant/ServantProxyFactory.h @@ -48,6 +48,8 @@ class ServantProxyFactory : public TC_ThreadRecMutex * @return ServantPrx */ ServantPrx::element_type* getServantProxy(const string& name,const string& setName, bool rootServant); + + ServantProxy* setServantProxy(ServantProxy * proxy, const string& name,const string& setName, bool rootServant); private: /** diff --git a/servant/servant/StatReport.h b/servant/servant/StatReport.h index 2561222d..1d81e751 100644 --- a/servant/servant/StatReport.h +++ b/servant/servant/StatReport.h @@ -26,16 +26,7 @@ ///////////////////////////////////////////////////////////////////////// /* 属性上报使用方式: - StatReport report; - report->setReportInfo( pPtr,strMasterName,strMasterIp, 5 ); - vector v; - v.push_back(1000); - v.push_back(1001); - v.push_back(1002); - v.push_back(1003); - v.push_back(1004); - - PropertyReportPtr srPtr = report->createPropertyReport("test", PropertyReport::sum(), PropertyReport::dist(v)); + PropertyReportPtr srPtr = report->createPropertyReport("test", PropertyReport::sum()); srPtr->report(i); */ @@ -87,8 +78,6 @@ class StatReport : public TC_HandleBase, public TC_Thread, public TC_ThreadLock * @param strModuleIp, 模块ip * @param iReportInterval, 上报间隔单位秒 * @param iMaxReporSize一次最大上报包长度。 跟udp最大允许包8k、MTU长度1472有关,暂定取值范围[500-1400] - * @param iSampleRate, 采样比率1/1000 - * @param iMaxSampleCount, 最大采样数 * @param iReportTimeout, 上报接口调用的超时时间 * @param sContainer, 设置上报的容器名 */ @@ -98,8 +87,6 @@ class StatReport : public TC_HandleBase, public TC_Thread, public TC_ThreadLock const string& strModuleIp, const string& strSetDivision, int iReportInterval = 60, - int iSampleRate = 1000, - unsigned int iMaxSampleCount = 100, int iMaxReportSize = 1400, int iReportTimeout = 5000); @@ -244,10 +231,10 @@ class StatReport : public TC_HandleBase, public TC_Thread, public TC_ThreadLock */ static bool divison2SetInfo(const string& str, vector& vtSetInfo); - /* - * func: tars.xxxServer =>> xxxServer - */ - static string getServerName(string sModuleName); +// /* +// * func: tars.xxxServer =>> xxxServer +// */ +// static string getServerName(string sModuleName); private: @@ -301,10 +288,6 @@ class StatReport : public TC_HandleBase, public TC_Thread, public TC_ThreadLock string _ip; - int _sampleRate; //生成模块间调用时序图的采样比率 - - unsigned int _maxSampleCount; //1分钟内最大采样条数 - StatFPrx _statPrx; MapStatMicMsg _statMicMsgClient; @@ -317,11 +300,10 @@ class StatReport : public TC_HandleBase, public TC_Thread, public TC_ThreadLock map _statPropMsg; -private: +}; - size_t _retValueNumLimit; +//typedef TC_AutoPtr StatReportPtr; -}; /////////////////////////////////////////////////////////// } diff --git a/servant/tup/Tars.h b/servant/tup/Tars.h index 1361694c..dc0279e7 100755 --- a/servant/tup/Tars.h +++ b/servant/tup/Tars.h @@ -2221,9 +2221,6 @@ class TarsOutputStream : public WriterT { write(i->first, 0); write(i->second, 1); - - std::cout << "write:" << i->first << ", " << i->second << std::endl; - } } } diff --git a/tools/tars2cpp/tars2cpp.cpp b/tools/tars2cpp/tars2cpp.cpp index 1859105b..5c714f67 100755 --- a/tools/tars2cpp/tars2cpp.cpp +++ b/tools/tars2cpp/tars2cpp.cpp @@ -1425,7 +1425,7 @@ string Tars2Cpp::generateDispatchAsync(const OperationPtr& pPtr, const string& c DEL_TAB; s << TAB << "}" << endl; - s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; + s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, \"\", getModuleName(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; DEL_TAB; s << TAB << "}" << endl; s << endl; @@ -1843,7 +1843,7 @@ string Tars2Cpp::generateServantDispatch(const OperationPtr& pPtr, const string& DEL_TAB; s << TAB << "}" << endl; - s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SR), TRACE_ANNOTATION_SR, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; + s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SR), TRACE_ANNOTATION_SR, \"\", getModuleName(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; DEL_TAB; s << TAB << "}" << endl; s << endl; @@ -2035,7 +2035,7 @@ string Tars2Cpp::generateServantDispatch(const OperationPtr& pPtr, const string& s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl; DEL_TAB; s << TAB << "}" << endl; - s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS), TRACE_ANNOTATION_SS, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; + s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_SS), TRACE_ANNOTATION_SS, \"\", getModuleName(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; DEL_TAB; s << TAB << "}" << endl; s << endl; @@ -2205,7 +2205,7 @@ string Tars2Cpp::generateHAsync(const OperationPtr& pPtr, const string& cn) cons s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl; DEL_TAB; s << TAB << "}" << endl; - s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + \".\" + ServerConfig::ServerName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; + s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, tars_moduleName(), tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; DEL_TAB; s << TAB << "}" << endl; } @@ -2232,7 +2232,10 @@ string Tars2Cpp::generateHAsync(const OperationPtr& pPtr, const string& cn) cons s << TAB << "this->tars_setMasterFlag(true);" << endl; } s << TAB << "tars::Promise< " << cn <<"PrxCallbackPromise::Promise" << sStruct << "Ptr > promise;" << endl; - s << TAB << cn << "PrxCallbackPromisePtr callback = new " << cn << "PrxCallbackPromise(promise);" << endl; + +// s << TAB << cn << "PrxCallbackPromisePtr callback = new " << cn << "PrxCallbackPromise(promise);" << endl; + s << TAB << cn << "PrxCallbackPromisePtr callback (new " << cn << "PrxCallbackPromise(promise));" << endl; + s << endl; s << TAB << _namespace + "::TarsOutputStream<" + _namespace + "::BufferWriterVector> _os;" << endl; for(size_t i = 0; i < vParamDecl.size(); i++) @@ -2401,7 +2404,7 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl; DEL_TAB; s << TAB << "}" << endl; - s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, ServerConfig::Application + \".\" + ServerConfig::ServerName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; + s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CS), TRACE_ANNOTATION_CS, tars_moduleName(), tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; DEL_TAB; s << TAB << "}" << endl; s << endl; @@ -2480,7 +2483,7 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl; DEL_TAB; s << TAB << "}" << endl; - s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, ServerConfig::Application + \".\" + ServerConfig::ServerName, tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; + s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, tars_moduleName(), tars_name(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; DEL_TAB; s << TAB << "}" << endl; s << endl; @@ -2499,7 +2502,7 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string INC_TAB; s << TAB << "TARS_TRACE(_pSptd_->getTraceKey(ServantProxyThreadData::TraceContext::EST_CR), TRACE_ANNOTATION_CR, \"\", \"\", \"" << pPtr->getId() << "\", 0, \"\", \"\");" << endl; DEL_TAB; - s << "}" << endl; + s << TAB << "}" << endl; } DEL_TAB; s << TAB << "}" << endl; @@ -2567,7 +2570,7 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string s << endl; s << TAB << "vector sTupResponseBuffer;" << endl; s << TAB << "_tarsAttr_.encode(sTupResponseBuffer);"<< endl; - s << TAB << "_current_->sendResponse(tars::TARSSERVERSUCCESS, sTupResponseBuffer);" << endl; + s << TAB << "_current_->sendResponse(tars::TARSSERVERSUCCESS, _tarsAttr_);" << endl; if (_bTrace) { s << TAB << "_rsp_len_ = sTupResponseBuffer.size();" << endl; @@ -2669,7 +2672,12 @@ string Tars2Cpp::generateH(const OperationPtr& pPtr, bool bVirtual, const string s << TAB << "_trace_param_ = " << G_TRACE_PARAM_OVER_MAX_LEN << ";" << endl; DEL_TAB; s << TAB << "}" << endl; - s << TAB << "TARS_TRACE(_current_->getTraceKey(), TRACE_ANNOTATION_SS, \"\", ServerConfig::Application + \".\" + ServerConfig::ServerName, \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; + s << TAB << "if(_current_->getServantHandle())" << endl; + s << TAB << "{" << endl; + INC_TAB; + s << TAB << "TARS_TRACE(_current_->getTraceKey(), TRACE_ANNOTATION_SS, \"\", _current_->getModuleName(), \"" << pPtr->getId() << "\", 0, _trace_param_, \"\");" << endl; + DEL_TAB; + s << TAB << "}" << endl; DEL_TAB; s << TAB << "}" << endl; s << endl; @@ -2777,7 +2785,12 @@ string Tars2Cpp::generateHPromiseAsync(const InterfacePtr &pInter, const Operati DEL_TAB; s << TAB << "};" << endl; s << TAB << endl; +#ifdef TARS_STD_SHARED_PTR + s << TAB << "typedef std::shared_ptr< " << pInter->getId() << "PrxCallbackPromise::Promise" << sStruct << " > Promise" << sStruct << "Ptr;" << endl; +#else s << TAB << "typedef tars::TC_AutoPtr< " << pInter->getId() << "PrxCallbackPromise::Promise" << sStruct << " > Promise" << sStruct << "Ptr;" << endl; +#endif + s << endl; s << TAB << pInter->getId() << "PrxCallbackPromise(const tars::Promise< " << pInter->getId() << "PrxCallbackPromise::Promise" << sStruct << "Ptr > &promise)" << endl; s << TAB << ": _promise_" << sStruct << "(promise)" << endl; @@ -2822,7 +2835,9 @@ string Tars2Cpp::generateDispatchPromiseAsync(const OperationPtr &pPtr, const st s << TAB << "_is.setBuffer(_msg_->response->sBuffer);" << endl; s << endl; string sStruct = pPtr->getId(); - s << TAB << cn << "PrxCallbackPromise::Promise" << sStruct << "Ptr ptr = new "<< cn << "PrxCallbackPromise::Promise" << sStruct << "();" << endl; + +// s << TAB << cn << "PrxCallbackPromise::Promise" << sStruct << "Ptr ptr = new "<< cn << "PrxCallbackPromise::Promise" << sStruct << "();" << endl; + s << TAB << cn << "PrxCallbackPromise::Promise" << sStruct << "Ptr ptr (new "<< cn << "PrxCallbackPromise::Promise" << sStruct << "());" << endl; s << endl; if(pPtr->getReturnPtr()->getTypePtr() || vParamDecl.size() >0) { @@ -2981,7 +2996,12 @@ string Tars2Cpp::generateH(const InterfacePtr &pPtr, const NamespacePtr &nPtr) c DEL_TAB; s << TAB << "};" << endl; +#ifdef TARS_STD_SHARED_PTR + s << TAB << "typedef std::shared_ptr<" << pPtr->getId() << "PrxCallback> " << pPtr->getId() << "PrxCallbackPtr;" << endl; +#else s << TAB << "typedef tars::TC_AutoPtr<" << pPtr->getId() << "PrxCallback> " << pPtr->getId() << "PrxCallbackPtr;" << endl; +#endif + s << endl; //生成promise异步回调Proxy s << TAB << "//callback of promise async proxy for client" << endl; @@ -3039,7 +3059,12 @@ string Tars2Cpp::generateH(const InterfacePtr &pPtr, const NamespacePtr &nPtr) c s << endl; DEL_TAB; s << TAB << "};" << endl; + +#ifdef TARS_STD_SHARED_PTR + s << TAB << "typedef std::shared_ptr<" << pPtr->getId() << "PrxCallbackPromise> " << pPtr->getId() << "PrxCallbackPromisePtr;" << endl; +#else s << TAB << "typedef tars::TC_AutoPtr<" << pPtr->getId() << "PrxCallbackPromise> " << pPtr->getId() << "PrxCallbackPromisePtr;" << endl; +#endif s << endl; //生成协程异步回调类,用于并发请求 s << TAB << "/* callback of coroutine async proxy for client */" << endl; @@ -3126,8 +3151,11 @@ string Tars2Cpp::generateH(const InterfacePtr &pPtr, const NamespacePtr &nPtr) c DEL_TAB; s << TAB << "};" << endl; - +#ifdef TARS_STD_SHARED_PTR + s << TAB << "typedef std::shared_ptr<" << pPtr->getId() << "CoroPrxCallback> " << pPtr->getId() << "CoroPrxCallbackPtr;" << endl; +#else s << TAB << "typedef tars::TC_AutoPtr<" << pPtr->getId() << "CoroPrxCallback> " << pPtr->getId() << "CoroPrxCallbackPtr;" << endl; +#endif s << endl; //生成客户端代理 @@ -3440,11 +3468,8 @@ void Tars2Cpp::generateH(const ContextPtr &pPtr) const { s << "#include \"servant/ServantProxy.h\"" << endl; s << "#include \"servant/Servant.h\"" << endl; - s << "#include \"promise/promise.h\"" << endl; - if (_bTrace) - { - s << "#include \"servant/Application.h\"" << endl; - } + s << "#include \"promise/promise.h\"" << endl; + break; } } diff --git a/tools/tarsgrammar/tars.tab.cpp b/tools/tarsgrammar/tars.tab.cpp index ee40db41..4647924b 100644 --- a/tools/tarsgrammar/tars.tab.cpp +++ b/tools/tarsgrammar/tars.tab.cpp @@ -1,8 +1,9 @@ -/* A Bison parser, made by GNU Bison 3.0.4. */ +/* A Bison parser, made by GNU Bison 3.7.6. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -33,6 +34,10 @@ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. @@ -40,11 +45,11 @@ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -/* Identify Bison output. */ -#define YYBISON 1 +/* Identify Bison output, and Bison version. */ +#define YYBISON 30706 -/* Bison version. */ -#define YYBISON_VERSION "3.0.4" +/* Bison version string. */ +#define YYBISON_VERSION "3.7.6" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -61,8 +66,8 @@ -/* Copy the first part of user declarations. */ -#line 17 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:339 */ +/* First part of user prologue. */ +#line 17 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" #include #include @@ -76,119 +81,213 @@ using namespace std; #define YYDEBUG 1 #define YYINITDEPTH 10000 -#line 80 "tars.tab.cpp" /* yacc.c:339 */ +#line 85 "tars.tab.cpp" +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif # ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif # else -# define YY_NULLPTR 0 +# define YY_NULLPTR ((void*)0) # endif # endif -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -/* In a future release of Bison, this section will be replaced - by #include "tars.tab.hpp". */ -#ifndef YY_YY_TARS_TAB_HPP_INCLUDED -# define YY_YY_TARS_TAB_HPP_INCLUDED -/* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 1 -#endif -#if YYDEBUG -extern int yydebug; -#endif - -/* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - TARS_VOID = 258, - TARS_STRUCT = 259, - TARS_BOOL = 260, - TARS_BYTE = 261, - TARS_SHORT = 262, - TARS_INT = 263, - TARS_DOUBLE = 264, - TARS_FLOAT = 265, - TARS_LONG = 266, - TARS_STRING = 267, - TARS_VECTOR = 268, - TARS_MAP = 269, - TARS_NAMESPACE = 270, - TARS_INTERFACE = 271, - TARS_IDENTIFIER = 272, - TARS_OUT = 273, - TARS_OP = 274, - TARS_KEY = 275, - TARS_ROUTE_KEY = 276, - TARS_REQUIRE = 277, - TARS_OPTIONAL = 278, - TARS_CONST_INTEGER = 279, - TARS_CONST_FLOAT = 280, - TARS_FALSE = 281, - TARS_TRUE = 282, - TARS_STRING_LITERAL = 283, - TARS_SCOPE_DELIMITER = 284, - TARS_CONST = 285, - TARS_ENUM = 286, - TARS_UNSIGNED = 287, - BAD_CHAR = 288 - }; -#endif +#include "tars.tab.hpp" +/* Symbol kind. */ +enum yysymbol_kind_t +{ + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_TARS_VOID = 3, /* TARS_VOID */ + YYSYMBOL_TARS_STRUCT = 4, /* TARS_STRUCT */ + YYSYMBOL_TARS_BOOL = 5, /* TARS_BOOL */ + YYSYMBOL_TARS_BYTE = 6, /* TARS_BYTE */ + YYSYMBOL_TARS_SHORT = 7, /* TARS_SHORT */ + YYSYMBOL_TARS_INT = 8, /* TARS_INT */ + YYSYMBOL_TARS_DOUBLE = 9, /* TARS_DOUBLE */ + YYSYMBOL_TARS_FLOAT = 10, /* TARS_FLOAT */ + YYSYMBOL_TARS_LONG = 11, /* TARS_LONG */ + YYSYMBOL_TARS_STRING = 12, /* TARS_STRING */ + YYSYMBOL_TARS_VECTOR = 13, /* TARS_VECTOR */ + YYSYMBOL_TARS_MAP = 14, /* TARS_MAP */ + YYSYMBOL_TARS_NAMESPACE = 15, /* TARS_NAMESPACE */ + YYSYMBOL_TARS_INTERFACE = 16, /* TARS_INTERFACE */ + YYSYMBOL_TARS_IDENTIFIER = 17, /* TARS_IDENTIFIER */ + YYSYMBOL_TARS_OUT = 18, /* TARS_OUT */ + YYSYMBOL_TARS_OP = 19, /* TARS_OP */ + YYSYMBOL_TARS_KEY = 20, /* TARS_KEY */ + YYSYMBOL_TARS_ROUTE_KEY = 21, /* TARS_ROUTE_KEY */ + YYSYMBOL_TARS_REQUIRE = 22, /* TARS_REQUIRE */ + YYSYMBOL_TARS_OPTIONAL = 23, /* TARS_OPTIONAL */ + YYSYMBOL_TARS_CONST_INTEGER = 24, /* TARS_CONST_INTEGER */ + YYSYMBOL_TARS_CONST_FLOAT = 25, /* TARS_CONST_FLOAT */ + YYSYMBOL_TARS_FALSE = 26, /* TARS_FALSE */ + YYSYMBOL_TARS_TRUE = 27, /* TARS_TRUE */ + YYSYMBOL_TARS_STRING_LITERAL = 28, /* TARS_STRING_LITERAL */ + YYSYMBOL_TARS_SCOPE_DELIMITER = 29, /* TARS_SCOPE_DELIMITER */ + YYSYMBOL_TARS_CONST = 30, /* TARS_CONST */ + YYSYMBOL_TARS_ENUM = 31, /* TARS_ENUM */ + YYSYMBOL_TARS_UNSIGNED = 32, /* TARS_UNSIGNED */ + YYSYMBOL_BAD_CHAR = 33, /* BAD_CHAR */ + YYSYMBOL_34_ = 34, /* ';' */ + YYSYMBOL_35_ = 35, /* '{' */ + YYSYMBOL_36_ = 36, /* '}' */ + YYSYMBOL_37_ = 37, /* ',' */ + YYSYMBOL_38_ = 38, /* '=' */ + YYSYMBOL_39_ = 39, /* '[' */ + YYSYMBOL_40_ = 40, /* ']' */ + YYSYMBOL_41_ = 41, /* ')' */ + YYSYMBOL_42_ = 42, /* '*' */ + YYSYMBOL_43_ = 43, /* ':' */ + YYSYMBOL_44_ = 44, /* '<' */ + YYSYMBOL_45_ = 45, /* '>' */ + YYSYMBOL_YYACCEPT = 46, /* $accept */ + YYSYMBOL_start = 47, /* start */ + YYSYMBOL_definitions = 48, /* definitions */ + YYSYMBOL_49_1 = 49, /* $@1 */ + YYSYMBOL_50_2 = 50, /* $@2 */ + YYSYMBOL_definition = 51, /* definition */ + YYSYMBOL_enum_def = 52, /* enum_def */ + YYSYMBOL_53_3 = 53, /* @3 */ + YYSYMBOL_enum_id = 54, /* enum_id */ + YYSYMBOL_enumerator_list = 55, /* enumerator_list */ + YYSYMBOL_enumerator = 56, /* enumerator */ + YYSYMBOL_namespace_def = 57, /* namespace_def */ + YYSYMBOL_58_4 = 58, /* @4 */ + YYSYMBOL_key_def = 59, /* key_def */ + YYSYMBOL_60_5 = 60, /* $@5 */ + YYSYMBOL_key_members = 61, /* key_members */ + YYSYMBOL_interface_def = 62, /* interface_def */ + YYSYMBOL_63_6 = 63, /* @6 */ + YYSYMBOL_interface_id = 64, /* interface_id */ + YYSYMBOL_interface_exports = 65, /* interface_exports */ + YYSYMBOL_interface_export = 66, /* interface_export */ + YYSYMBOL_operation = 67, /* operation */ + YYSYMBOL_operation_preamble = 68, /* operation_preamble */ + YYSYMBOL_return_type = 69, /* return_type */ + YYSYMBOL_parameters = 70, /* parameters */ + YYSYMBOL_routekey_qualifier = 71, /* routekey_qualifier */ + YYSYMBOL_out_qualifier = 72, /* out_qualifier */ + YYSYMBOL_struct_def = 73, /* struct_def */ + YYSYMBOL_74_7 = 74, /* @7 */ + YYSYMBOL_struct_id = 75, /* struct_id */ + YYSYMBOL_struct_exports = 76, /* struct_exports */ + YYSYMBOL_data_member = 77, /* data_member */ + YYSYMBOL_struct_type_id = 78, /* struct_type_id */ + YYSYMBOL_const_initializer = 79, /* const_initializer */ + YYSYMBOL_const_def = 80, /* const_def */ + YYSYMBOL_type_id = 81, /* type_id */ + YYSYMBOL_type = 82, /* type */ + YYSYMBOL_type_no = 83, /* type_no */ + YYSYMBOL_vector = 84, /* vector */ + YYSYMBOL_map = 85, /* map */ + YYSYMBOL_scoped_name = 86, /* scoped_name */ + YYSYMBOL_keyword = 87 /* keyword */ +}; +typedef enum yysymbol_kind_t yysymbol_kind_t; -/* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef int YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 -#endif -extern YYSTYPE yylval; -int yyparse (void); +#ifdef short +# undef short +#endif -#endif /* !YY_YY_TARS_TAB_HPP_INCLUDED */ +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ -/* Copy the second part of user declarations. */ +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif +#endif -#line 165 "tars.tab.cpp" /* yacc.c:358 */ +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ -#ifdef short -# undef short +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else +typedef signed char yytype_int8; #endif -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; #else -typedef unsigned char yytype_uint8; +typedef short yytype_int16; #endif -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; -#else -typedef signed char yytype_int8; +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + . */ +#ifdef __hpux +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 #endif -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; #else -typedef unsigned short int yytype_uint16; +typedef short yytype_uint8; #endif -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; #else -typedef short int yytype_int16; +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif #endif #ifndef YYSIZE_T @@ -196,15 +295,28 @@ typedef short int yytype_int16; # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif ! defined YYSIZE_T +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else -# define YYSIZE_T unsigned int +# define YYSIZE_T unsigned # endif #endif -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + + +/* Stored state numbers (used for stacks). */ +typedef yytype_uint8 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS @@ -218,47 +330,37 @@ typedef short int yytype_int16; # endif #endif -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif -#endif #ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define YY_ATTRIBUTE_PURE +# endif #endif #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) -#endif - -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) # else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) +# define YY_ATTRIBUTE_UNUSED # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +# define YY_USE(E) ((void) (E)) #else -# define YYUSE(E) /* empty */ +# define YY_USE(E) /* empty */ #endif -#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ _Pragma ("GCC diagnostic pop") #else # define YY_INITIAL_VALUE(Value) Value @@ -271,8 +373,22 @@ typedef short int yytype_int16; # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + -#if ! defined yyoverflow || YYERROR_VERBOSE +#define YY_ASSERT(E) ((void) (0 && (E))) + +#if !defined yyoverflow /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -337,8 +453,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - +#endif /* !defined yyoverflow */ #if (! defined yyoverflow \ && (! defined __cplusplus \ @@ -347,17 +462,17 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss_alloc; + yy_state_t yyss_alloc; YYSTYPE yyvs_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) # define YYCOPY_NEEDED 1 @@ -370,11 +485,11 @@ union yyalloc # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ - YYSIZE_T yynewbytes; \ + YYPTRDIFF_T yynewbytes; \ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ } \ while (0) @@ -386,12 +501,12 @@ union yyalloc # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) # else # define YYCOPY(Dst, Src, Count) \ do \ { \ - YYSIZE_T yyi; \ + YYPTRDIFF_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (Dst)[yyi] = (Src)[yyi]; \ } \ @@ -414,17 +529,20 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES 199 -/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned - by yylex, with out-of-bounds checking. */ -#define YYUNDEFTOK 2 +/* YYMAXUTOK -- Last valid token kind. */ #define YYMAXUTOK 288 -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM - as returned by yylex, without out-of-bounds checking. */ -static const yytype_uint8 yytranslate[] = + as returned by yylex. */ +static const yytype_int8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -459,7 +577,7 @@ static const yytype_uint8 yytranslate[] = #if YYDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = +static const yytype_int16 yyrline[] = { 0, 68, 68, 75, 74, 79, 78, 83, 88, 95, 99, 103, 107, 110, 114, 124, 123, 146, 159, 170, @@ -478,35 +596,48 @@ static const yytype_uint16 yyrline[] = }; #endif -#if YYDEBUG || YYERROR_VERBOSE || 0 +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if YYDEBUG || 0 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "$end", "error", "$undefined", "TARS_VOID", "TARS_STRUCT", "TARS_BOOL", - "TARS_BYTE", "TARS_SHORT", "TARS_INT", "TARS_DOUBLE", "TARS_FLOAT", - "TARS_LONG", "TARS_STRING", "TARS_VECTOR", "TARS_MAP", "TARS_NAMESPACE", - "TARS_INTERFACE", "TARS_IDENTIFIER", "TARS_OUT", "TARS_OP", "TARS_KEY", - "TARS_ROUTE_KEY", "TARS_REQUIRE", "TARS_OPTIONAL", "TARS_CONST_INTEGER", - "TARS_CONST_FLOAT", "TARS_FALSE", "TARS_TRUE", "TARS_STRING_LITERAL", - "TARS_SCOPE_DELIMITER", "TARS_CONST", "TARS_ENUM", "TARS_UNSIGNED", - "BAD_CHAR", "';'", "'{'", "'}'", "','", "'='", "'['", "']'", "')'", - "'*'", "':'", "'<'", "'>'", "$accept", "start", "definitions", "$@1", - "$@2", "definition", "enum_def", "@3", "enum_id", "enumerator_list", - "enumerator", "namespace_def", "@4", "key_def", "$@5", "key_members", - "interface_def", "@6", "interface_id", "interface_exports", - "interface_export", "operation", "operation_preamble", "return_type", - "parameters", "routekey_qualifier", "out_qualifier", "struct_def", "@7", - "struct_id", "struct_exports", "data_member", "struct_type_id", - "const_initializer", "const_def", "type_id", "type", "type_no", "vector", - "map", "scoped_name", "keyword", YY_NULLPTR + "\"end of file\"", "error", "\"invalid token\"", "TARS_VOID", + "TARS_STRUCT", "TARS_BOOL", "TARS_BYTE", "TARS_SHORT", "TARS_INT", + "TARS_DOUBLE", "TARS_FLOAT", "TARS_LONG", "TARS_STRING", "TARS_VECTOR", + "TARS_MAP", "TARS_NAMESPACE", "TARS_INTERFACE", "TARS_IDENTIFIER", + "TARS_OUT", "TARS_OP", "TARS_KEY", "TARS_ROUTE_KEY", "TARS_REQUIRE", + "TARS_OPTIONAL", "TARS_CONST_INTEGER", "TARS_CONST_FLOAT", "TARS_FALSE", + "TARS_TRUE", "TARS_STRING_LITERAL", "TARS_SCOPE_DELIMITER", "TARS_CONST", + "TARS_ENUM", "TARS_UNSIGNED", "BAD_CHAR", "';'", "'{'", "'}'", "','", + "'='", "'['", "']'", "')'", "'*'", "':'", "'<'", "'>'", "$accept", + "start", "definitions", "$@1", "$@2", "definition", "enum_def", "@3", + "enum_id", "enumerator_list", "enumerator", "namespace_def", "@4", + "key_def", "$@5", "key_members", "interface_def", "@6", "interface_id", + "interface_exports", "interface_export", "operation", + "operation_preamble", "return_type", "parameters", "routekey_qualifier", + "out_qualifier", "struct_def", "@7", "struct_id", "struct_exports", + "data_member", "struct_type_id", "const_initializer", "const_def", + "type_id", "type", "type_no", "vector", "map", "scoped_name", "keyword", YY_NULLPTR }; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +} #endif -# ifdef YYPRINT +#ifdef YYPRINT /* YYTOKNUM[NUM] -- (External) token number corresponding to the (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = +static const yytype_int16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, @@ -514,16 +645,16 @@ static const yytype_uint16 yytoknum[] = 285, 286, 287, 288, 59, 123, 125, 44, 61, 91, 93, 41, 42, 58, 60, 62 }; -# endif +#endif -#define YYPACT_NINF -146 +#define YYPACT_NINF (-146) -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-146))) +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) -#define YYTABLE_NINF -113 +#define YYTABLE_NINF (-113) -#define yytable_value_is_error(Yytable_value) \ +#define yytable_value_is_error(Yyn) \ 0 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing @@ -590,9 +721,9 @@ static const yytype_int16 yypgoto[] = }; /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int16 yydefgoto[] = +static const yytype_uint8 yydefgoto[] = { - -1, 8, 9, 76, 80, 10, 11, 77, 12, 123, + 0, 8, 9, 76, 80, 10, 11, 77, 12, 123, 124, 13, 81, 14, 142, 171, 15, 78, 16, 128, 129, 130, 131, 132, 157, 158, 159, 17, 79, 18, 137, 138, 139, 113, 19, 140, 68, 69, 70, 71, @@ -726,7 +857,7 @@ static const yytype_int16 yycheck[] = /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = +static const yytype_int8 yystos[] = { 0, 1, 4, 15, 16, 20, 30, 31, 47, 48, 51, 52, 54, 57, 59, 62, 64, 73, 75, 80, @@ -751,7 +882,7 @@ static const yytype_uint8 yystos[] = }; /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = +static const yytype_int8 yyr1[] = { 0, 46, 47, 49, 48, 50, 48, 48, 48, 51, 51, 51, 51, 51, 51, 53, 52, 54, 54, 55, @@ -770,7 +901,7 @@ static const yytype_uint8 yyr1[] = }; /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = +static const yytype_int8 yyr2[] = { 0, 2, 1, 0, 4, 0, 4, 1, 0, 1, 1, 1, 1, 1, 1, 0, 5, 2, 2, 3, @@ -789,10 +920,10 @@ static const yytype_uint8 yyr2[] = }; +enum { YYENOMEM = -2 }; + #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab @@ -801,27 +932,26 @@ static const yytype_uint8 yyr2[] = #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (0) - -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) + +/* Backward compatibility with an undocumented macro. + Use YYerror or YYUNDEF. */ +#define YYERRCODE YYUNDEF /* Enable debugging if requested. */ @@ -839,54 +969,58 @@ do { \ } while (0) /* This macro is provided for backward compatibility. */ -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif +# ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value); \ + Kind, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) -/*----------------------------------------. -| Print this symbol's value on YYOUTPUT. | -`----------------------------------------*/ +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) { - FILE *yyo = yyoutput; - YYUSE (yyo); + FILE *yyoutput = yyo; + YY_USE (yyoutput); if (!yyvaluep) return; # ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); + if (yykind < YYNTOKENS) + YYPRINT (yyo, yytoknum[yykind], *yyvaluep); # endif - YYUSE (yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END } -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) { - YYFPRINTF (yyoutput, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + YYFPRINTF (yyo, "%s %s (", + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); - yy_symbol_value_print (yyoutput, yytype, yyvaluep); - YYFPRINTF (yyoutput, ")"); + yy_symbol_value_print (yyo, yykind, yyvaluep); + YYFPRINTF (yyo, ")"); } /*------------------------------------------------------------------. @@ -895,7 +1029,7 @@ yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) `------------------------------------------------------------------*/ static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -918,21 +1052,21 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, + int yyrule) { - unsigned long int yylno = yyrline[yyrule]; + int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &(yyvsp[(yyi + 1) - (yynrhs)]) - ); + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)]); YYFPRINTF (stderr, "\n"); } } @@ -947,8 +1081,8 @@ do { \ multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ @@ -971,249 +1105,30 @@ int yydebug; #endif -#if YYERROR_VERBOSE -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -static YYSIZE_T -yystrlen (const char *yystr) -{ - YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; -} -# endif -# endif -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -static char * -yystpcpy (char *yydest, const char *yysrc) -{ - char *yyd = yydest; - const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - return yyd - 1; -} -# endif -# endif - -# ifndef yytnamerr -/* Copy to YYRES the contents of YYSTR after stripping away unnecessary - quotes and backslashes, so that it's suitable for yyerror. The - heuristic is that double-quoting is unnecessary unless the string - contains an apostrophe, a comma, or backslash (other than - backslash-backslash). YYSTR is taken from yytname. If YYRES is - null, do not copy; instead, return the length of what the result - would have been. */ -static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } - - if (! yyres) - return yystrlen (yystr); - - return yystpcpy (yyres, yystr) - yyres; -} -# endif - -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ -static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) -{ - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ - int yycount = 0; - - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } - } - } - - switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } - - { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } - - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } - } - return 0; -} -#endif /* YYERROR_VERBOSE */ /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep) { - YYUSE (yyvaluep); + YY_USE (yyvaluep); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE (yytype); + YY_USE (yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END } - - -/* The lookahead symbol. */ +/* Lookahead token kind. */ int yychar; /* The semantic value of the lookahead symbol. */ @@ -1222,6 +1137,8 @@ YYSTYPE yylval; int yynerrs; + + /*----------. | yyparse. | `----------*/ @@ -1229,43 +1146,36 @@ int yynerrs; int yyparse (void) { - int yystate; + yy_state_fast_t yystate = 0; /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; + int yyerrstatus = 0; - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. - - Refer to the stacks through separate pointers, to allow yyoverflow + /* Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + /* Their size. */ + YYPTRDIFF_T yystacksize = YYINITDEPTH; - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss = yyssa; + yy_state_t *yyssp = yyss; - YYSIZE_T yystacksize; + /* The semantic value stack: array, bottom, top. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp = yyvs; int yyn; + /* The return value of yyparse. */ int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif + #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) @@ -1273,58 +1183,60 @@ yyparse (void) Keep to zero when no symbol should be popped. */ int yylen = 0; - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yystacksize = YYINITDEPTH; - YYDPRINTF ((stderr, "Starting parse\n")); - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; + /*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | +| yynewstate -- push a new state, which is found in yystate. | `------------------------------------------------------------*/ - yynewstate: +yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; - yysetstate: - *yyssp = yystate; + +/*--------------------------------------------------------------------. +| yysetstate -- set current state (the top of the stack) to yystate. | +`--------------------------------------------------------------------*/ +yysetstate: + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); if (yyss + yystacksize - 1 <= yyssp) +#if !defined yyoverflow && !defined YYSTACK_RELOCATE + goto yyexhaustedlab; +#else { /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; + YYPTRDIFF_T yysize = yyssp - yyss + 1; -#ifdef yyoverflow +# if defined yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ + yy_state_t *yyss1 = yyss; YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp), &yystacksize); - yyss = yyss1; yyvs = yyvs1; } -#else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyexhaustedlab; -# else +# else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; @@ -1333,9 +1245,10 @@ yyparse (void) yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; + yy_state_t *yyss1 = yyss; union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); @@ -1345,30 +1258,30 @@ yyparse (void) YYSTACK_FREE (yyss1); } # endif -#endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) YYABORT; } - - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); +#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ if (yystate == YYFINAL) YYACCEPT; goto yybackup; + /*-----------. | yybackup. | `-----------*/ yybackup: - /* Do appropriate processing given the current state. Read a lookahead token if we need one and don't already have one. */ @@ -1379,18 +1292,29 @@ yyparse (void) /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ if (yychar == YYEMPTY) { - YYDPRINTF ((stderr, "Reading a token: ")); + YYDPRINTF ((stderr, "Reading a token\n")); yychar = yylex (); } if (yychar <= YYEOF) { - yychar = yytoken = YYEOF; + yychar = YYEOF; + yytoken = YYSYMBOL_YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } + else if (yychar == YYerror) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = YYUNDEF; + yytoken = YYSYMBOL_YYerror; + goto yyerrlab1; + } else { yytoken = YYTRANSLATE (yychar); @@ -1418,15 +1342,13 @@ yyparse (void) /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - yychar = YYEMPTY; - yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END + /* Discard the shifted token. */ + yychar = YYEMPTY; goto yynewstate; @@ -1441,7 +1363,7 @@ yyparse (void) /*-----------------------------. -| yyreduce -- Do a reduction. | +| yyreduce -- do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ @@ -1461,238 +1383,238 @@ yyparse (void) YY_REDUCE_PRINT (yyn); switch (yyn) { - case 3: -#line 75 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 3: /* $@1: %empty */ +#line 75 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1469 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1391 "tars.tab.cpp" break; - case 5: -#line 79 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 5: /* $@2: %empty */ +#line 79 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ yyerrok; } -#line 1477 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1399 "tars.tab.cpp" break; - case 7: -#line 84 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 7: /* definitions: definition */ +#line 84 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("`;' missing after definition"); } -#line 1485 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1407 "tars.tab.cpp" break; - case 8: -#line 88 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 8: /* definitions: %empty */ +#line 88 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1492 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1414 "tars.tab.cpp" break; - case 9: -#line 96 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - assert((yyvsp[0]) == 0 || NamespacePtr::dynamicCast((yyvsp[0]))); + case 9: /* definition: namespace_def */ +#line 96 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + assert(yyvsp[0] == 0 || NamespacePtr::dynamicCast(yyvsp[0])); } -#line 1500 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1422 "tars.tab.cpp" break; - case 10: -#line 100 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - assert((yyvsp[0]) == 0 || InterfacePtr::dynamicCast((yyvsp[0]))); + case 10: /* definition: interface_def */ +#line 100 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + assert(yyvsp[0] == 0 || InterfacePtr::dynamicCast(yyvsp[0])); } -#line 1508 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1430 "tars.tab.cpp" break; - case 11: -#line 104 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - assert((yyvsp[0]) == 0 || StructPtr::dynamicCast((yyvsp[0]))); + case 11: /* definition: struct_def */ +#line 104 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + assert(yyvsp[0] == 0 || StructPtr::dynamicCast(yyvsp[0])); } -#line 1516 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1438 "tars.tab.cpp" break; - case 12: -#line 108 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 12: /* definition: key_def */ +#line 108 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1523 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1445 "tars.tab.cpp" break; - case 13: -#line 111 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - assert((yyvsp[0]) == 0 || EnumPtr::dynamicCast((yyvsp[0]))); + case 13: /* definition: enum_def */ +#line 111 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + assert(yyvsp[0] == 0 || EnumPtr::dynamicCast(yyvsp[0])); } -#line 1531 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1453 "tars.tab.cpp" break; - case 14: -#line 115 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - assert((yyvsp[0]) == 0 || ConstPtr::dynamicCast((yyvsp[0]))); + case 14: /* definition: const_def */ +#line 115 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + assert(yyvsp[0] == 0 || ConstPtr::dynamicCast(yyvsp[0])); } -#line 1539 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1461 "tars.tab.cpp" break; - case 15: -#line 124 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = (yyvsp[0]); + case 15: /* @3: %empty */ +#line 124 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = yyvsp[0]; } -#line 1547 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1469 "tars.tab.cpp" break; - case 16: -#line 128 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - if((yyvsp[-2])) + case 16: /* enum_def: enum_id @3 '{' enumerator_list '}' */ +#line 128 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + if(yyvsp[-2]) { g_parse->popContainer(); - (yyval) = (yyvsp[-2]); + yyval = yyvsp[-2]; } else { - (yyval) = 0; + yyval = 0; } - (yyval) = (yyvsp[-3]); + yyval = yyvsp[-3]; } -#line 1565 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1487 "tars.tab.cpp" break; - case 17: -#line 147 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 17: /* enum_id: TARS_ENUM TARS_IDENTIFIER */ +#line 147 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ NamespacePtr c = NamespacePtr::dynamicCast(g_parse->currentContainer()); if(!c) { g_parse->error("enum must define in namespace"); } - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); EnumPtr e = c->createEnum(ident->v); g_parse->pushContainer(e); - (yyval) = e; + yyval = e; } -#line 1582 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1504 "tars.tab.cpp" break; - case 18: -#line 160 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 18: /* enum_id: TARS_ENUM keyword */ +#line 160 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); g_parse->error("keyword `" + ident->v + "' cannot be used as enumeration name"); - (yyval) = (yyvsp[0]); + yyval = yyvsp[0]; } -#line 1592 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1514 "tars.tab.cpp" break; - case 19: -#line 171 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = (yyvsp[-1]); + case 19: /* enumerator_list: enumerator ',' enumerator_list */ +#line 171 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = yyvsp[-1]; } -#line 1600 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1522 "tars.tab.cpp" break; - case 20: -#line 175 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 20: /* enumerator_list: enumerator */ +#line 175 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1607 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1529 "tars.tab.cpp" break; - case 21: -#line 183 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 21: /* enumerator: TARS_IDENTIFIER */ +#line 183 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ TypePtr type = TypePtr::dynamicCast(g_parse->createBuiltin(Builtin::KindLong)); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); TypeIdPtr tPtr = new TypeId(type, ident->v); tPtr->disableDefault(); EnumPtr e = EnumPtr::dynamicCast(g_parse->currentContainer()); assert(e); e->addMember(tPtr); - (yyval) = e; + yyval = e; } -#line 1622 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1544 "tars.tab.cpp" break; - case 22: -#line 194 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 22: /* enumerator: keyword */ +#line 194 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); g_parse->error("keyword `" + ident->v + "' cannot be used as enumerator"); } -#line 1631 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1553 "tars.tab.cpp" break; - case 23: -#line 199 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 23: /* enumerator: TARS_IDENTIFIER '=' const_initializer */ +#line 199 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ TypePtr type = TypePtr::dynamicCast(g_parse->createBuiltin(Builtin::KindLong)); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[-2])); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-2]); TypeIdPtr tPtr = new TypeId(type, ident->v); - ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast((yyvsp[0])); + ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast(yyvsp[0]); g_parse->checkConstValue(tPtr, sPtr->t); tPtr->setDefault(sPtr->v); EnumPtr e = EnumPtr::dynamicCast(g_parse->currentContainer()); assert(e); e->addMember(tPtr); - (yyval) = e; + yyval = e; } -#line 1648 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1570 "tars.tab.cpp" break; - case 24: -#line 212 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 24: /* enumerator: %empty */ +#line 212 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1655 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1577 "tars.tab.cpp" break; - case 25: -#line 220 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 25: /* @4: %empty */ +#line 220 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); ContainerPtr c = g_parse->currentContainer(); NamespacePtr n = c->createNamespace(ident->v); if(n) { g_parse->pushContainer(n); - (yyval) = GrammarBasePtr::dynamicCast(n); + yyval = GrammarBasePtr::dynamicCast(n); } else { - (yyval) = 0; + yyval = 0; } } -#line 1674 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1596 "tars.tab.cpp" break; - case 26: -#line 235 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - if((yyvsp[-3])) + case 26: /* namespace_def: TARS_NAMESPACE TARS_IDENTIFIER @4 '{' definitions '}' */ +#line 235 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + if(yyvsp[-3]) { g_parse->popContainer(); - (yyval) = (yyvsp[-3]); + yyval = yyvsp[-3]; } else { - (yyval) = 0; + yyval = 0; } } -#line 1690 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1612 "tars.tab.cpp" break; - case 27: -#line 253 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[-1])); + case 27: /* $@5: %empty */ +#line 253 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-1]); StructPtr sp = StructPtr::dynamicCast(g_parse->findUserType(ident->v)); if(!sp) { @@ -1701,20 +1623,20 @@ yyparse (void) g_parse->setKeyStruct(sp); } -#line 1705 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1627 "tars.tab.cpp" break; - case 28: -#line 264 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 28: /* key_def: TARS_KEY '[' scoped_name ',' $@5 key_members ']' */ +#line 264 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1712 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1634 "tars.tab.cpp" break; - case 29: -#line 272 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 29: /* key_members: TARS_IDENTIFIER */ +#line 272 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); StructPtr np = g_parse->getKeyStruct(); if(np) { @@ -1722,16 +1644,16 @@ yyparse (void) } else { - (yyval) = 0; + yyval = 0; } } -#line 1729 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1651 "tars.tab.cpp" break; - case 30: -#line 285 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 30: /* key_members: key_members ',' TARS_IDENTIFIER */ +#line 285 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); StructPtr np = g_parse->getKeyStruct(); if(np) { @@ -1739,16 +1661,16 @@ yyparse (void) } else { - (yyval) = 0; + yyval = 0; } } -#line 1746 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1668 "tars.tab.cpp" break; - case 31: -#line 304 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 31: /* @6: %empty */ +#line 304 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); NamespacePtr c = NamespacePtr::dynamicCast(g_parse->currentContainer()); @@ -1756,100 +1678,100 @@ yyparse (void) if(cl) { g_parse->pushContainer(cl); - (yyval) = GrammarBasePtr::dynamicCast(cl); + yyval = GrammarBasePtr::dynamicCast(cl); } else { - (yyval) = 0; + yyval = 0; } } -#line 1767 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1689 "tars.tab.cpp" break; - case 32: -#line 321 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - if((yyvsp[-3])) + case 32: /* interface_def: interface_id @6 '{' interface_exports '}' */ +#line 321 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + if(yyvsp[-3]) { g_parse->popContainer(); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-3])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[-3]); } else { - (yyval) = 0; + yyval = 0; } } -#line 1783 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1705 "tars.tab.cpp" break; - case 33: -#line 338 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = (yyvsp[0]); + case 33: /* interface_id: TARS_INTERFACE TARS_IDENTIFIER */ +#line 338 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = yyvsp[0]; } -#line 1791 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1713 "tars.tab.cpp" break; - case 34: -#line 342 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 34: /* interface_id: TARS_INTERFACE keyword */ +#line 342 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); g_parse->error("keyword `" + ident->v + "' cannot be used as interface name"); - (yyval) = (yyvsp[0]); + yyval = yyvsp[0]; } -#line 1801 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1723 "tars.tab.cpp" break; - case 35: -#line 353 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 35: /* interface_exports: interface_export ';' interface_exports */ +#line 353 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1808 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1730 "tars.tab.cpp" break; - case 36: -#line 356 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 36: /* interface_exports: error ';' interface_exports */ +#line 356 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1815 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1737 "tars.tab.cpp" break; - case 37: -#line 359 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 37: /* interface_exports: interface_export */ +#line 359 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("`;' missing after definition"); } -#line 1823 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1745 "tars.tab.cpp" break; - case 38: -#line 363 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 38: /* interface_exports: %empty */ +#line 363 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1830 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1752 "tars.tab.cpp" break; - case 40: -#line 377 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - if((yyvsp[-2])) + case 40: /* operation: operation_preamble parameters ')' */ +#line 377 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + if(yyvsp[-2]) { g_parse->popContainer(); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-2])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[-2]); } else { - (yyval) = 0; + yyval = 0; } } -#line 1846 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1768 "tars.tab.cpp" break; - case 41: -#line 394 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypePtr returnType = TypePtr::dynamicCast((yyvsp[-1])); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 41: /* operation_preamble: return_type TARS_OP */ +#line 394 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypePtr returnType = TypePtr::dynamicCast(yyvsp[-1]); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); string name = ident->v; InterfacePtr cl = InterfacePtr::dynamicCast(g_parse->currentContainer()); if(cl) @@ -1858,40 +1780,40 @@ yyparse (void) if(op) { g_parse->pushContainer(op); - (yyval) = GrammarBasePtr::dynamicCast(op); + yyval = GrammarBasePtr::dynamicCast(op); } else { - (yyval) = 0; + yyval = 0; } } else { - (yyval) = 0; + yyval = 0; } } -#line 1874 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1796 "tars.tab.cpp" break; - case 43: -#line 424 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = 0; + case 43: /* return_type: TARS_VOID */ +#line 424 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = 0; } -#line 1882 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1804 "tars.tab.cpp" break; - case 44: -#line 434 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 44: /* parameters: %empty */ +#line 434 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1889 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1811 "tars.tab.cpp" break; - case 45: -#line 437 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 45: /* parameters: type_id */ +#line 437 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1900,13 +1822,13 @@ yyparse (void) op->createParamDecl(tsp, false, false); } } -#line 1904 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1826 "tars.tab.cpp" break; - case 46: -#line 448 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 46: /* parameters: parameters ',' type_id */ +#line 448 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1915,14 +1837,14 @@ yyparse (void) op->createParamDecl(tsp, false, false); } } -#line 1919 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1841 "tars.tab.cpp" break; - case 47: -#line 459 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast((yyvsp[-1])); - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 47: /* parameters: out_qualifier type_id */ +#line 459 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1931,14 +1853,14 @@ yyparse (void) op->createParamDecl(tsp, isOutParam->v, false); } } -#line 1935 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1857 "tars.tab.cpp" break; - case 48: -#line 471 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast((yyvsp[-1])); - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 48: /* parameters: parameters ',' out_qualifier type_id */ +#line 471 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1947,14 +1869,14 @@ yyparse (void) op->createParamDecl(tsp, isOutParam->v, false); } } -#line 1951 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1873 "tars.tab.cpp" break; - case 49: -#line 483 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast((yyvsp[-1])); - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 49: /* parameters: routekey_qualifier type_id */ +#line 483 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1963,14 +1885,14 @@ yyparse (void) op->createParamDecl(tsp, false, isRouteKeyParam->v); } } -#line 1967 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1889 "tars.tab.cpp" break; - case 50: -#line 495 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast((yyvsp[-1])); - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 50: /* parameters: parameters ',' routekey_qualifier type_id */ +#line 495 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1979,49 +1901,49 @@ yyparse (void) op->createParamDecl(tsp, false, isRouteKeyParam->v); } } -#line 1983 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1905 "tars.tab.cpp" break; - case 51: -#line 507 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 51: /* parameters: out_qualifier */ +#line 507 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("'out' must be defined with a type"); } -#line 1991 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1913 "tars.tab.cpp" break; - case 52: -#line 511 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 52: /* parameters: routekey_qualifier */ +#line 511 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("'routekey' must be defined with a type"); } -#line 1999 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1921 "tars.tab.cpp" break; - case 53: -#line 520 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 53: /* routekey_qualifier: TARS_ROUTE_KEY */ +#line 520 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ BoolGrammarPtr routekey = new BoolGrammar; routekey->v = true; - (yyval) = GrammarBasePtr::dynamicCast(routekey); + yyval = GrammarBasePtr::dynamicCast(routekey); } -#line 2009 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1931 "tars.tab.cpp" break; - case 54: -#line 531 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 54: /* out_qualifier: TARS_OUT */ +#line 531 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ BoolGrammarPtr out = new BoolGrammar; out->v = true; - (yyval) = GrammarBasePtr::dynamicCast(out); + yyval = GrammarBasePtr::dynamicCast(out); } -#line 2019 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1941 "tars.tab.cpp" break; - case 55: -#line 542 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 55: /* @7: %empty */ +#line 542 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); NamespacePtr np = NamespacePtr::dynamicCast(g_parse->currentContainer()); if(np) { @@ -2029,11 +1951,11 @@ yyparse (void) if(sp) { g_parse->pushContainer(sp); - (yyval) = GrammarBasePtr::dynamicCast(sp); + yyval = GrammarBasePtr::dynamicCast(sp); } else { - (yyval) = 0; + yyval = 0; } } else @@ -2041,280 +1963,280 @@ yyparse (void) g_parse->error("struct '" + ident->v + "' must definition in namespace"); } } -#line 2045 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1967 "tars.tab.cpp" break; - case 56: -#line 564 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - if((yyvsp[-3])) + case 56: /* struct_def: struct_id @7 '{' struct_exports '}' */ +#line 564 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + if(yyvsp[-3]) { g_parse->popContainer(); } - (yyval) = (yyvsp[-3]); + yyval = yyvsp[-3]; - StructPtr st = StructPtr::dynamicCast((yyval)); + StructPtr st = StructPtr::dynamicCast(yyval); assert(st); if(st->getAllMemberPtr().size() == 0) { g_parse->error("struct `" + st->getSid() + "' must have at least one member"); } } -#line 2064 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1986 "tars.tab.cpp" break; - case 57: -#line 584 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = (yyvsp[0]); + case 57: /* struct_id: TARS_STRUCT TARS_IDENTIFIER */ +#line 584 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = yyvsp[0]; } -#line 2072 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1994 "tars.tab.cpp" break; - case 58: -#line 588 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 58: /* struct_id: TARS_STRUCT keyword */ +#line 588 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); g_parse->error("keyword `" + ident->v + "' cannot be used as struct name"); } -#line 2082 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2004 "tars.tab.cpp" break; - case 59: -#line 594 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 59: /* struct_id: TARS_STRUCT error */ +#line 594 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("abstract declarator '' used as declaration"); } -#line 2090 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2012 "tars.tab.cpp" break; - case 60: -#line 603 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 60: /* struct_exports: data_member ';' struct_exports */ +#line 603 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2098 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2020 "tars.tab.cpp" break; - case 61: -#line 607 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 61: /* struct_exports: data_member */ +#line 607 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("';' missing after definition"); } -#line 2106 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2028 "tars.tab.cpp" break; - case 62: -#line 611 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 62: /* struct_exports: %empty */ +#line 611 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2113 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2035 "tars.tab.cpp" break; - case 63: -#line 621 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); + case 63: /* data_member: struct_type_id */ +#line 621 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); } -#line 2121 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2043 "tars.tab.cpp" break; - case 64: -#line 630 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 64: /* struct_type_id: TARS_CONST_INTEGER TARS_REQUIRE type_id */ +#line 630 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ StructPtr np = StructPtr::dynamicCast(g_parse->currentContainer()); if(np) { - IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast((yyvsp[-2])); + IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast(yyvsp[-2]); g_parse->checkTag(iPtr->v); - TypeIdPtr tPtr = TypeIdPtr::dynamicCast((yyvsp[0])); + TypeIdPtr tPtr = TypeIdPtr::dynamicCast(yyvsp[0]); tPtr->setRequire(iPtr->v); np->addTypeId(tPtr); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); } else { - (yyval) = 0; + yyval = 0; } } -#line 2143 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2065 "tars.tab.cpp" break; - case 65: -#line 648 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 65: /* struct_type_id: TARS_CONST_INTEGER TARS_REQUIRE type_id '=' const_initializer */ +#line 648 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ StructPtr np = StructPtr::dynamicCast(g_parse->currentContainer()); if(np) { - IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast((yyvsp[-4])); + IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast(yyvsp[-4]); g_parse->checkTag(iPtr->v); - TypeIdPtr tPtr = TypeIdPtr::dynamicCast((yyvsp[-2])); - ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast((yyvsp[0])); + TypeIdPtr tPtr = TypeIdPtr::dynamicCast(yyvsp[-2]); + ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast(yyvsp[0]); g_parse->checkConstValue(tPtr, sPtr->t); tPtr->setRequire(iPtr->v); tPtr->setDefault(sPtr->v); np->addTypeId(tPtr); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-2])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[-2]); } else { - (yyval) = 0; + yyval = 0; } } -#line 2169 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2091 "tars.tab.cpp" break; - case 66: -#line 670 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 66: /* struct_type_id: TARS_CONST_INTEGER TARS_OPTIONAL type_id '=' const_initializer */ +#line 670 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ StructPtr np = StructPtr::dynamicCast(g_parse->currentContainer()); if(np) { - IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast((yyvsp[-4])); + IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast(yyvsp[-4]); g_parse->checkTag(iPtr->v); - TypeIdPtr tPtr = TypeIdPtr::dynamicCast((yyvsp[-2])); - ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast((yyvsp[0])); + TypeIdPtr tPtr = TypeIdPtr::dynamicCast(yyvsp[-2]); + ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast(yyvsp[0]); g_parse->checkConstValue(tPtr, sPtr->t); tPtr->setOptional(iPtr->v); tPtr->setDefault(sPtr->v); np->addTypeId(tPtr); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-2])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[-2]); } else { - (yyval) = 0; + yyval = 0; } } -#line 2195 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2117 "tars.tab.cpp" break; - case 67: -#line 692 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 67: /* struct_type_id: TARS_CONST_INTEGER TARS_OPTIONAL type_id */ +#line 692 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ StructPtr np = StructPtr::dynamicCast(g_parse->currentContainer()); if(np) { - IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast((yyvsp[-2])); + IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast(yyvsp[-2]); g_parse->checkTag(iPtr->v); - TypeIdPtr tPtr = TypeIdPtr::dynamicCast((yyvsp[0])); + TypeIdPtr tPtr = TypeIdPtr::dynamicCast(yyvsp[0]); tPtr->setOptional(iPtr->v); np->addTypeId(tPtr); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); } else { - (yyval) = 0; + yyval = 0; } } -#line 2216 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2138 "tars.tab.cpp" break; - case 68: -#line 709 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 68: /* struct_type_id: TARS_REQUIRE type_id */ +#line 709 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("struct member need 'tag'"); } -#line 2224 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2146 "tars.tab.cpp" break; - case 69: -#line 713 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 69: /* struct_type_id: TARS_OPTIONAL type_id */ +#line 713 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("struct member need 'tag'"); } -#line 2232 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2154 "tars.tab.cpp" break; - case 70: -#line 717 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 70: /* struct_type_id: TARS_CONST_INTEGER type_id */ +#line 717 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("struct member need 'require' or 'optional'"); } -#line 2240 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2162 "tars.tab.cpp" break; - case 71: -#line 721 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 71: /* struct_type_id: type_id */ +#line 721 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("struct member need 'tag' or 'require' or 'optional'"); } -#line 2248 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2170 "tars.tab.cpp" break; - case 72: -#line 730 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - IntergerGrammarPtr intVal = IntergerGrammarPtr::dynamicCast((yyvsp[0])); + case 72: /* const_initializer: TARS_CONST_INTEGER */ +#line 730 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + IntergerGrammarPtr intVal = IntergerGrammarPtr::dynamicCast(yyvsp[0]); ostringstream sstr; sstr << intVal->v; ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::VALUE; c->v = sstr.str(); - (yyval) = c; + yyval = c; } -#line 2262 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2184 "tars.tab.cpp" break; - case 73: -#line 740 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - FloatGrammarPtr floatVal = FloatGrammarPtr::dynamicCast((yyvsp[0])); + case 73: /* const_initializer: TARS_CONST_FLOAT */ +#line 740 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + FloatGrammarPtr floatVal = FloatGrammarPtr::dynamicCast(yyvsp[0]); ostringstream sstr; sstr << floatVal->v; ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::VALUE; c->v = sstr.str(); - (yyval) = c; + yyval = c; } -#line 2276 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2198 "tars.tab.cpp" break; - case 74: -#line 750 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 74: /* const_initializer: TARS_STRING_LITERAL */ +#line 750 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::STRING; c->v = ident->v; - (yyval) = c; + yyval = c; } -#line 2288 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2210 "tars.tab.cpp" break; - case 75: -#line 758 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 75: /* const_initializer: TARS_FALSE */ +#line 758 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::BOOL; c->v = ident->v; - (yyval) = c; + yyval = c; } -#line 2300 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2222 "tars.tab.cpp" break; - case 76: -#line 766 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 76: /* const_initializer: TARS_TRUE */ +#line 766 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::BOOL; c->v = ident->v; - (yyval) = c; + yyval = c; } -#line 2312 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2234 "tars.tab.cpp" break; - case 77: -#line 774 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 77: /* const_initializer: TARS_IDENTIFIER */ +#line 774 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); if (g_parse->checkEnum(ident->v) == false) { @@ -2323,17 +2245,17 @@ yyparse (void) ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::ENUM; c->v = ident->v; - (yyval) = c; + yyval = c; } -#line 2329 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2251 "tars.tab.cpp" break; - case 78: -#line 787 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 78: /* const_initializer: scoped_name TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ +#line 787 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ - StringGrammarPtr scoped = StringGrammarPtr::dynamicCast((yyvsp[-2])); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + StringGrammarPtr scoped = StringGrammarPtr::dynamicCast(yyvsp[-2]); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); if (g_parse->checkEnum(ident->v) == false) { @@ -2342,511 +2264,512 @@ yyparse (void) ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::ENUM; c->v = scoped->v + "::" + ident->v; - (yyval) = c; + yyval = c; } -#line 2348 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2270 "tars.tab.cpp" break; - case 79: -#line 807 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 79: /* const_def: TARS_CONST type_id '=' const_initializer */ +#line 807 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ NamespacePtr np = NamespacePtr::dynamicCast(g_parse->currentContainer()); if(!np) { g_parse->error("const type must define in namespace"); } - TypeIdPtr t = TypeIdPtr::dynamicCast((yyvsp[-2])); - ConstGrammarPtr c = ConstGrammarPtr::dynamicCast((yyvsp[0])); + TypeIdPtr t = TypeIdPtr::dynamicCast(yyvsp[-2]); + ConstGrammarPtr c = ConstGrammarPtr::dynamicCast(yyvsp[0]); ConstPtr cPtr = np->createConst(t, c); - (yyval) = cPtr; + yyval = cPtr; } -#line 2365 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2287 "tars.tab.cpp" break; - case 80: -#line 825 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypePtr type = TypePtr::dynamicCast((yyvsp[-1])); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 80: /* type_id: type TARS_IDENTIFIER */ +#line 825 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypePtr type = TypePtr::dynamicCast(yyvsp[-1]); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); TypeIdPtr typeIdPtr = new TypeId(type, ident->v); - (yyval) = GrammarBasePtr::dynamicCast(typeIdPtr); + yyval = GrammarBasePtr::dynamicCast(typeIdPtr); } -#line 2378 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2300 "tars.tab.cpp" break; - case 81: -#line 834 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypePtr type = g_parse->createVector(TypePtr::dynamicCast((yyvsp[-4]))); - IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast((yyvsp[-1])); + case 81: /* type_id: type TARS_IDENTIFIER '[' TARS_CONST_INTEGER ']' */ +#line 834 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypePtr type = g_parse->createVector(TypePtr::dynamicCast(yyvsp[-4])); + IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast(yyvsp[-1]); g_parse->checkArrayVaid(type,iPtrSize->v); type->setArray(iPtrSize->v); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[-3])); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-3]); TypeIdPtr typeIdPtr = new TypeId(type, ident->v); - (yyval) = GrammarBasePtr::dynamicCast(typeIdPtr); + yyval = GrammarBasePtr::dynamicCast(typeIdPtr); } -#line 2392 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2314 "tars.tab.cpp" break; - case 82: -#line 844 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypePtr type = g_parse->createVector(TypePtr::dynamicCast((yyvsp[-2]))); + case 82: /* type_id: type '*' TARS_IDENTIFIER */ +#line 844 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypePtr type = g_parse->createVector(TypePtr::dynamicCast(yyvsp[-2])); //IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast($4); g_parse->checkPointerVaid(type); type->setPointer(true); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); TypeIdPtr typeIdPtr = new TypeId(type, ident->v); - (yyval) = GrammarBasePtr::dynamicCast(typeIdPtr); + yyval = GrammarBasePtr::dynamicCast(typeIdPtr); } -#line 2406 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2328 "tars.tab.cpp" break; - case 83: -#line 854 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypePtr type = TypePtr::dynamicCast((yyvsp[-3])); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[-2])); + case 83: /* type_id: type TARS_IDENTIFIER ':' TARS_CONST_INTEGER */ +#line 854 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypePtr type = TypePtr::dynamicCast(yyvsp[-3]); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-2]); TypeIdPtr typeIdPtr = new TypeId(type, ident->v); - IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast((yyvsp[-1])); + IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast(yyvsp[-1]); g_parse->checkArrayVaid(type,iPtrSize->v); - (yyval) = GrammarBasePtr::dynamicCast(typeIdPtr); + yyval = GrammarBasePtr::dynamicCast(typeIdPtr); } -#line 2419 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2341 "tars.tab.cpp" break; - case 84: -#line 863 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 84: /* type_id: type keyword */ +#line 863 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); g_parse->error("keyword `" + ident->v + "' cannot be used as data member name"); } -#line 2428 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2350 "tars.tab.cpp" break; - case 85: -#line 868 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 85: /* type_id: type */ +#line 868 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("missing data member name"); } -#line 2436 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2358 "tars.tab.cpp" break; - case 86: -#line 872 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 86: /* type_id: error */ +#line 872 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("unkown type"); } -#line 2444 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2366 "tars.tab.cpp" break; - case 87: -#line 881 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 87: /* type: type_no ':' TARS_CONST_INTEGER */ +#line 881 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ - TypePtr type = TypePtr::dynamicCast((yyvsp[-2])); - IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast((yyvsp[0])); + TypePtr type = TypePtr::dynamicCast(yyvsp[-2]); + IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast(yyvsp[0]); g_parse->checkArrayVaid(type,iPtrSize->v); type->setArray(iPtrSize->v); - (yyval) = type; + yyval = type; } -#line 2457 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2379 "tars.tab.cpp" break; - case 88: -#line 890 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = (yyvsp[0]); + case 88: /* type: type_no */ +#line 890 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = yyvsp[0]; } -#line 2465 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2387 "tars.tab.cpp" break; - case 89: -#line 894 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 89: /* type: type_no ':' error */ +#line 894 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("array missing size"); } -#line 2473 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2395 "tars.tab.cpp" break; - case 90: -#line 903 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindBool); + case 90: /* type_no: TARS_BOOL */ +#line 903 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindBool); } -#line 2481 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2403 "tars.tab.cpp" break; - case 91: -#line 907 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindByte); + case 91: /* type_no: TARS_BYTE */ +#line 907 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindByte); } -#line 2489 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2411 "tars.tab.cpp" break; - case 92: -#line 911 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindShort,true); + case 92: /* type_no: TARS_UNSIGNED TARS_BYTE */ +#line 911 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindShort,true); } -#line 2497 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2419 "tars.tab.cpp" break; - case 93: -#line 915 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindShort); + case 93: /* type_no: TARS_SHORT */ +#line 915 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindShort); } -#line 2505 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2427 "tars.tab.cpp" break; - case 94: -#line 919 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindInt,true); + case 94: /* type_no: TARS_UNSIGNED TARS_SHORT */ +#line 919 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindInt,true); } -#line 2513 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2435 "tars.tab.cpp" break; - case 95: -#line 923 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindInt); + case 95: /* type_no: TARS_INT */ +#line 923 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindInt); } -#line 2521 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2443 "tars.tab.cpp" break; - case 96: -#line 927 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindLong,true); + case 96: /* type_no: TARS_UNSIGNED TARS_INT */ +#line 927 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindLong,true); } -#line 2529 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2451 "tars.tab.cpp" break; - case 97: -#line 931 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindLong); + case 97: /* type_no: TARS_LONG */ +#line 931 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindLong); } -#line 2537 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2459 "tars.tab.cpp" break; - case 98: -#line 935 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindFloat); + case 98: /* type_no: TARS_FLOAT */ +#line 935 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindFloat); } -#line 2545 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2467 "tars.tab.cpp" break; - case 99: -#line 939 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindDouble); + case 99: /* type_no: TARS_DOUBLE */ +#line 939 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindDouble); } -#line 2553 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2475 "tars.tab.cpp" break; - case 100: -#line 943 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindString); + case 100: /* type_no: TARS_STRING */ +#line 943 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindString); } -#line 2561 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2483 "tars.tab.cpp" break; - case 101: -#line 947 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); + case 101: /* type_no: vector */ +#line 947 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); } -#line 2569 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2491 "tars.tab.cpp" break; - case 102: -#line 951 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); + case 102: /* type_no: map */ +#line 951 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); } -#line 2577 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2499 "tars.tab.cpp" break; - case 103: -#line 955 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 103: /* type_no: scoped_name */ +#line 955 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); TypePtr sp = g_parse->findUserType(ident->v); if(sp) { - (yyval) = GrammarBasePtr::dynamicCast(sp); + yyval = GrammarBasePtr::dynamicCast(sp); } else { g_parse->error("'" + ident->v + "' undefined!"); } } -#line 2594 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2516 "tars.tab.cpp" break; - case 104: -#line 973 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = GrammarBasePtr::dynamicCast(g_parse->createVector(TypePtr::dynamicCast((yyvsp[-1])))); + case 104: /* vector: TARS_VECTOR '<' type '>' */ +#line 973 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = GrammarBasePtr::dynamicCast(g_parse->createVector(TypePtr::dynamicCast(yyvsp[-1]))); } -#line 2602 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2524 "tars.tab.cpp" break; - case 105: -#line 977 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 105: /* vector: TARS_VECTOR '<' error */ +#line 977 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("vector error"); } -#line 2610 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2532 "tars.tab.cpp" break; - case 106: -#line 981 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 106: /* vector: TARS_VECTOR '<' type error */ +#line 981 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("vector missing '>'"); } -#line 2618 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2540 "tars.tab.cpp" break; - case 107: -#line 985 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 107: /* vector: TARS_VECTOR error */ +#line 985 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("vector missing type"); } -#line 2626 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2548 "tars.tab.cpp" break; - case 108: -#line 994 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = GrammarBasePtr::dynamicCast(g_parse->createMap(TypePtr::dynamicCast((yyvsp[-3])), TypePtr::dynamicCast((yyvsp[-1])))); + case 108: /* map: TARS_MAP '<' type ',' type '>' */ +#line 994 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = GrammarBasePtr::dynamicCast(g_parse->createMap(TypePtr::dynamicCast(yyvsp[-3]), TypePtr::dynamicCast(yyvsp[-1]))); } -#line 2634 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2556 "tars.tab.cpp" break; - case 109: -#line 998 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 109: /* map: TARS_MAP '<' error */ +#line 998 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("map error"); } -#line 2642 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2564 "tars.tab.cpp" break; - case 110: -#line 1007 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 110: /* scoped_name: TARS_IDENTIFIER */ +#line 1007 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2649 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2571 "tars.tab.cpp" break; - case 111: -#line 1010 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 111: /* scoped_name: TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ +#line 1010 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); ident->v = "::" + ident->v; - (yyval) = GrammarBasePtr::dynamicCast(ident); + yyval = GrammarBasePtr::dynamicCast(ident); } -#line 2659 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2581 "tars.tab.cpp" break; - case 112: -#line 1016 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr scoped = StringGrammarPtr::dynamicCast((yyvsp[-2])); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 112: /* scoped_name: scoped_name TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ +#line 1016 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr scoped = StringGrammarPtr::dynamicCast(yyvsp[-2]); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); scoped->v += "::"; scoped->v += ident->v; - (yyval) = GrammarBasePtr::dynamicCast(scoped); + yyval = GrammarBasePtr::dynamicCast(scoped); } -#line 2671 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2593 "tars.tab.cpp" break; - case 113: -#line 1029 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 113: /* keyword: TARS_STRUCT */ +#line 1029 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2678 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2600 "tars.tab.cpp" break; - case 114: -#line 1032 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 114: /* keyword: TARS_VOID */ +#line 1032 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2685 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2607 "tars.tab.cpp" break; - case 115: -#line 1035 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 115: /* keyword: TARS_BOOL */ +#line 1035 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2692 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2614 "tars.tab.cpp" break; - case 116: -#line 1038 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 116: /* keyword: TARS_BYTE */ +#line 1038 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2699 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2621 "tars.tab.cpp" break; - case 117: -#line 1041 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 117: /* keyword: TARS_SHORT */ +#line 1041 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2706 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2628 "tars.tab.cpp" break; - case 118: -#line 1044 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 118: /* keyword: TARS_INT */ +#line 1044 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2713 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2635 "tars.tab.cpp" break; - case 119: -#line 1047 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 119: /* keyword: TARS_FLOAT */ +#line 1047 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2720 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2642 "tars.tab.cpp" break; - case 120: -#line 1050 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 120: /* keyword: TARS_DOUBLE */ +#line 1050 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2727 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2649 "tars.tab.cpp" break; - case 121: -#line 1053 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 121: /* keyword: TARS_STRING */ +#line 1053 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2734 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2656 "tars.tab.cpp" break; - case 122: -#line 1056 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 122: /* keyword: TARS_VECTOR */ +#line 1056 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2741 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2663 "tars.tab.cpp" break; - case 123: -#line 1059 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 123: /* keyword: TARS_KEY */ +#line 1059 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2748 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2670 "tars.tab.cpp" break; - case 124: -#line 1062 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 124: /* keyword: TARS_MAP */ +#line 1062 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2755 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2677 "tars.tab.cpp" break; - case 125: -#line 1065 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 125: /* keyword: TARS_NAMESPACE */ +#line 1065 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2762 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2684 "tars.tab.cpp" break; - case 126: -#line 1068 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 126: /* keyword: TARS_INTERFACE */ +#line 1068 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2769 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2691 "tars.tab.cpp" break; - case 127: -#line 1071 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 127: /* keyword: TARS_OUT */ +#line 1071 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2776 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2698 "tars.tab.cpp" break; - case 128: -#line 1074 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 128: /* keyword: TARS_REQUIRE */ +#line 1074 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2783 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2705 "tars.tab.cpp" break; - case 129: -#line 1077 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 129: /* keyword: TARS_OPTIONAL */ +#line 1077 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2790 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2712 "tars.tab.cpp" break; - case 130: -#line 1080 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 130: /* keyword: TARS_CONST_INTEGER */ +#line 1080 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2797 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2719 "tars.tab.cpp" break; - case 131: -#line 1083 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 131: /* keyword: TARS_CONST_FLOAT */ +#line 1083 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2804 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2726 "tars.tab.cpp" break; - case 132: -#line 1086 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 132: /* keyword: TARS_FALSE */ +#line 1086 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2811 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2733 "tars.tab.cpp" break; - case 133: -#line 1089 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 133: /* keyword: TARS_TRUE */ +#line 1089 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2818 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2740 "tars.tab.cpp" break; - case 134: -#line 1092 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 134: /* keyword: TARS_STRING_LITERAL */ +#line 1092 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2825 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2747 "tars.tab.cpp" break; - case 135: -#line 1095 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 135: /* keyword: TARS_CONST */ +#line 1095 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2832 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2754 "tars.tab.cpp" break; - case 136: -#line 1098 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 136: /* keyword: TARS_ENUM */ +#line 1098 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2839 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2761 "tars.tab.cpp" break; - case 137: -#line 1101 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 137: /* keyword: TARS_UNSIGNED */ +#line 1101 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2846 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2768 "tars.tab.cpp" break; -#line 2850 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2772 "tars.tab.cpp" + default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2860,25 +2783,23 @@ yyparse (void) case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } goto yynewstate; @@ -2889,50 +2810,14 @@ yyparse (void) yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - + yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; -#if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif } - - if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an @@ -2961,12 +2846,10 @@ yyparse (void) | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: - - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (/*CONSTCOND*/ 0) - goto yyerrorlab; + /* Pacify compilers when the user code never invokes YYERROR and the + label yyerrorlab therefore never appears in user code. */ + if (0) + YYERROR; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ @@ -2983,13 +2866,14 @@ yyparse (void) yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ + /* Pop stack until we find a state that shifts the error token. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default (yyn)) { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + yyn += YYSYMBOL_YYerror; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) { yyn = yytable[yyn]; if (0 < yyn) @@ -3003,7 +2887,7 @@ yyparse (void) yydestruct ("Error: popping", - yystos[yystate], yyvsp); + YY_ACCESSING_SYMBOL (yystate), yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -3015,7 +2899,7 @@ yyparse (void) /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -3028,6 +2912,7 @@ yyparse (void) yyresult = 0; goto yyreturn; + /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ @@ -3035,16 +2920,21 @@ yyparse (void) yyresult = 1; goto yyreturn; -#if !defined yyoverflow || YYERROR_VERBOSE + +#if !defined yyoverflow /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; - /* Fall through. */ + goto yyreturn; #endif + +/*-------------------------------------------------------. +| yyreturn -- parsing is finished, clean up and return. | +`-------------------------------------------------------*/ yyreturn: if (yychar != YYEMPTY) { @@ -3061,20 +2951,18 @@ yyparse (void) while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp); + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); -#endif + return yyresult; } -#line 1105 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1906 */ + +#line 1105 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" diff --git a/tools/tarsparse/CMakeLists.txt b/tools/tarsparse/CMakeLists.txt index b47e3170..d9f7788e 100644 --- a/tools/tarsparse/CMakeLists.txt +++ b/tools/tarsparse/CMakeLists.txt @@ -37,3 +37,6 @@ endif(UNIX) install(TARGETS tarsparse LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) + +FILE(GLOB HEADERS "*.h") +install(FILES ${HEADERS} DESTINATION include/tarsparse) \ No newline at end of file diff --git a/tools/tarsparse/tars.lex.cpp b/tools/tarsparse/tars.lex.cpp index 4c5d318c..e7cd6524 100644 --- a/tools/tarsparse/tars.lex.cpp +++ b/tools/tarsparse/tars.lex.cpp @@ -1,6 +1,6 @@ -#line 2 "tars.lex.cpp" +#line 1 "tars.lex.cpp" -#line 4 "tars.lex.cpp" +#line 3 "tars.lex.cpp" #define YY_INT_ALIGNED short int @@ -47,6 +47,7 @@ typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; +typedef uint64_t flex_uint64_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; @@ -155,7 +156,7 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; typedef size_t yy_size_t; #endif -extern int yyleng; +extern yy_size_t yyleng; extern FILE *yyin, *yyout; @@ -172,7 +173,7 @@ extern FILE *yyin, *yyout; */ #define YY_LESS_LINENO(n) \ do { \ - int yyl;\ + yy_size_t yyl;\ for ( yyl = n; yyl < yyleng; ++yyl )\ if ( yytext[yyl] == '\n' )\ --yylineno;\ @@ -217,7 +218,7 @@ struct yy_buffer_state /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - int yy_n_chars; + yy_size_t yy_n_chars; /* Whether we "own" the buffer - i.e., we know we created it, * and can realloc() it to grow it, and should free() it to @@ -286,8 +287,8 @@ static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ /* yy_hold_char holds the character lost when yytext is formed. */ static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; +static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ +yy_size_t yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = NULL; @@ -314,7 +315,7 @@ static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file ); YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size ); YY_BUFFER_STATE yy_scan_string ( const char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, yy_size_t len ); void *yyalloc ( yy_size_t ); void *yyrealloc ( void *, yy_size_t ); @@ -367,7 +368,7 @@ static void yynoreturn yy_fatal_error ( const char* msg ); */ #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ - yyleng = (int) (yy_cp - yy_bp); \ + yyleng = (yy_size_t) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; @@ -510,7 +511,7 @@ int yy_flex_debug = 0; #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET char *yytext; -#line 1 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 1 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" /** * Tencent is pleased to support the open source community by making Tars available. * @@ -526,7 +527,7 @@ char *yytext; * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. */ -#line 20 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 20 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" #include #include #include @@ -597,7 +598,7 @@ FILE *yyget_out ( void ); void yyset_out ( FILE * _out_str ); - int yyget_leng ( void ); + yy_size_t yyget_leng ( void ); char *yyget_text ( void ); @@ -666,7 +667,7 @@ static int input ( void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - int n; \ + yy_size_t n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -775,7 +776,7 @@ YY_DECL } { -#line 67 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 67 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" #line 782 "tars.lex.cpp" @@ -826,7 +827,7 @@ YY_DECL if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) { - int yyl; + yy_size_t yyl; for ( yyl = 0; yyl < yyleng; ++yyl ) if ( yytext[yyl] == '\n' ) @@ -847,12 +848,12 @@ YY_DECL case 1: YY_RULE_SETUP -#line 69 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 69 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { BEGIN(INCL); } YY_BREAK case 2: YY_RULE_SETUP -#line 71 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 71 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { if ( include_file_stack_ptr >= MAX_INCLUDE_DEPTH ) { @@ -885,7 +886,7 @@ YY_RULE_SETUP YY_BREAK case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INCL): -#line 101 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 101 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { --include_file_stack_ptr; if ( include_file_stack_ptr < 0 ) @@ -904,14 +905,14 @@ case YY_STATE_EOF(INCL): YY_BREAK case 3: YY_RULE_SETUP -#line 117 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 117 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { return TARS_SCOPE_DELIMITER; } YY_BREAK case 4: YY_RULE_SETUP -#line 121 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 121 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { // C++ comment bool e = false; @@ -932,7 +933,7 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 139 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 139 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { // C comment bool e = false; @@ -983,7 +984,7 @@ YY_RULE_SETUP YY_BREAK case 6: YY_RULE_SETUP -#line 187 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 187 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { StringGrammarPtr ident = new StringGrammar; ident->v = yytext; @@ -994,7 +995,7 @@ YY_RULE_SETUP case 7: /* rule 7 can match eol */ YY_RULE_SETUP -#line 194 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 194 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { StringGrammarPtr ident = new StringGrammar; ident->v = yytext; @@ -1007,7 +1008,7 @@ YY_RULE_SETUP YY_BREAK case 8: YY_RULE_SETUP -#line 204 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 204 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { StringGrammarPtr str = new StringGrammar; bool e = false; @@ -1122,7 +1123,7 @@ YY_RULE_SETUP YY_BREAK case 9: YY_RULE_SETUP -#line 316 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 316 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { errno = 0; IntergerGrammarPtr ptr = new IntergerGrammar; @@ -1147,7 +1148,7 @@ YY_RULE_SETUP YY_BREAK case 10: YY_RULE_SETUP -#line 338 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 338 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { errno = 0; FloatGrammarPtr ptr = new FloatGrammar; @@ -1182,7 +1183,7 @@ YY_RULE_SETUP case 11: /* rule 11 can match eol */ YY_RULE_SETUP -#line 369 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 369 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { if(yytext[0] == '\n') { @@ -1192,7 +1193,7 @@ YY_RULE_SETUP YY_BREAK case 12: YY_RULE_SETUP -#line 376 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 376 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" { if(yytext[0] < 32 || yytext[0] > 126) { @@ -1211,7 +1212,7 @@ YY_RULE_SETUP YY_BREAK case 13: YY_RULE_SETUP -#line 392 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 392 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" ECHO; YY_BREAK #line 1218 "tars.lex.cpp" @@ -1399,7 +1400,7 @@ static int yy_get_next_buffer (void) else { - int num_to_read = + yy_size_t num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) @@ -1413,7 +1414,7 @@ static int yy_get_next_buffer (void) if ( b->yy_is_our_buffer ) { - int new_size = b->yy_buf_size * 2; + yy_size_t new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; @@ -1471,7 +1472,7 @@ static int yy_get_next_buffer (void) if (((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { /* Extend the array by 50%, plus the number we really need. */ - int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc( (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size ); if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) @@ -1560,7 +1561,7 @@ static int yy_get_next_buffer (void) if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) { /* need to shift things up to make room */ /* +2 for EOB chars. */ - int number_to_move = (yy_n_chars) + 2; + yy_size_t number_to_move = (yy_n_chars) + 2; char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; char *source = @@ -1615,7 +1616,7 @@ static int yy_get_next_buffer (void) else { /* need more input */ - int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); + yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) @@ -1989,12 +1990,12 @@ YY_BUFFER_STATE yy_scan_string (const char * yystr ) * * @return the newly allocated buffer state object. */ -YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, yy_size_t _yybytes_len ) { YY_BUFFER_STATE b; char *buf; yy_size_t n; - int i; + yy_size_t i; /* Get memory for full buffer, including space for trailing EOB's. */ n = (yy_size_t) (_yybytes_len + 2); @@ -2036,7 +2037,7 @@ static void yynoreturn yy_fatal_error (const char* msg ) do \ { \ /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ + yy_size_t yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ yytext[yyleng] = (yy_hold_char); \ (yy_c_buf_p) = yytext + yyless_macro_arg; \ @@ -2076,7 +2077,7 @@ FILE *yyget_out (void) /** Get the length of the current token. * */ -int yyget_leng (void) +yy_size_t yyget_leng (void) { return yyleng; } @@ -2229,7 +2230,7 @@ void yyfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 392 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" +#line 392 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.l" diff --git a/tools/tarsparse/tars.tab.cpp b/tools/tarsparse/tars.tab.cpp index ee40db41..4647924b 100644 --- a/tools/tarsparse/tars.tab.cpp +++ b/tools/tarsparse/tars.tab.cpp @@ -1,8 +1,9 @@ -/* A Bison parser, made by GNU Bison 3.0.4. */ +/* A Bison parser, made by GNU Bison 3.7.6. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -33,6 +34,10 @@ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. @@ -40,11 +45,11 @@ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -/* Identify Bison output. */ -#define YYBISON 1 +/* Identify Bison output, and Bison version. */ +#define YYBISON 30706 -/* Bison version. */ -#define YYBISON_VERSION "3.0.4" +/* Bison version string. */ +#define YYBISON_VERSION "3.7.6" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -61,8 +66,8 @@ -/* Copy the first part of user declarations. */ -#line 17 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:339 */ +/* First part of user prologue. */ +#line 17 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" #include #include @@ -76,119 +81,213 @@ using namespace std; #define YYDEBUG 1 #define YYINITDEPTH 10000 -#line 80 "tars.tab.cpp" /* yacc.c:339 */ +#line 85 "tars.tab.cpp" +# ifndef YY_CAST +# ifdef __cplusplus +# define YY_CAST(Type, Val) static_cast (Val) +# define YY_REINTERPRET_CAST(Type, Val) reinterpret_cast (Val) +# else +# define YY_CAST(Type, Val) ((Type) (Val)) +# define YY_REINTERPRET_CAST(Type, Val) ((Type) (Val)) +# endif +# endif # ifndef YY_NULLPTR -# if defined __cplusplus && 201103L <= __cplusplus -# define YY_NULLPTR nullptr +# if defined __cplusplus +# if 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif # else -# define YY_NULLPTR 0 +# define YY_NULLPTR ((void*)0) # endif # endif -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -/* In a future release of Bison, this section will be replaced - by #include "tars.tab.hpp". */ -#ifndef YY_YY_TARS_TAB_HPP_INCLUDED -# define YY_YY_TARS_TAB_HPP_INCLUDED -/* Debug traces. */ -#ifndef YYDEBUG -# define YYDEBUG 1 -#endif -#if YYDEBUG -extern int yydebug; -#endif - -/* Token type. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - enum yytokentype - { - TARS_VOID = 258, - TARS_STRUCT = 259, - TARS_BOOL = 260, - TARS_BYTE = 261, - TARS_SHORT = 262, - TARS_INT = 263, - TARS_DOUBLE = 264, - TARS_FLOAT = 265, - TARS_LONG = 266, - TARS_STRING = 267, - TARS_VECTOR = 268, - TARS_MAP = 269, - TARS_NAMESPACE = 270, - TARS_INTERFACE = 271, - TARS_IDENTIFIER = 272, - TARS_OUT = 273, - TARS_OP = 274, - TARS_KEY = 275, - TARS_ROUTE_KEY = 276, - TARS_REQUIRE = 277, - TARS_OPTIONAL = 278, - TARS_CONST_INTEGER = 279, - TARS_CONST_FLOAT = 280, - TARS_FALSE = 281, - TARS_TRUE = 282, - TARS_STRING_LITERAL = 283, - TARS_SCOPE_DELIMITER = 284, - TARS_CONST = 285, - TARS_ENUM = 286, - TARS_UNSIGNED = 287, - BAD_CHAR = 288 - }; -#endif +#include "tars.tab.hpp" +/* Symbol kind. */ +enum yysymbol_kind_t +{ + YYSYMBOL_YYEMPTY = -2, + YYSYMBOL_YYEOF = 0, /* "end of file" */ + YYSYMBOL_YYerror = 1, /* error */ + YYSYMBOL_YYUNDEF = 2, /* "invalid token" */ + YYSYMBOL_TARS_VOID = 3, /* TARS_VOID */ + YYSYMBOL_TARS_STRUCT = 4, /* TARS_STRUCT */ + YYSYMBOL_TARS_BOOL = 5, /* TARS_BOOL */ + YYSYMBOL_TARS_BYTE = 6, /* TARS_BYTE */ + YYSYMBOL_TARS_SHORT = 7, /* TARS_SHORT */ + YYSYMBOL_TARS_INT = 8, /* TARS_INT */ + YYSYMBOL_TARS_DOUBLE = 9, /* TARS_DOUBLE */ + YYSYMBOL_TARS_FLOAT = 10, /* TARS_FLOAT */ + YYSYMBOL_TARS_LONG = 11, /* TARS_LONG */ + YYSYMBOL_TARS_STRING = 12, /* TARS_STRING */ + YYSYMBOL_TARS_VECTOR = 13, /* TARS_VECTOR */ + YYSYMBOL_TARS_MAP = 14, /* TARS_MAP */ + YYSYMBOL_TARS_NAMESPACE = 15, /* TARS_NAMESPACE */ + YYSYMBOL_TARS_INTERFACE = 16, /* TARS_INTERFACE */ + YYSYMBOL_TARS_IDENTIFIER = 17, /* TARS_IDENTIFIER */ + YYSYMBOL_TARS_OUT = 18, /* TARS_OUT */ + YYSYMBOL_TARS_OP = 19, /* TARS_OP */ + YYSYMBOL_TARS_KEY = 20, /* TARS_KEY */ + YYSYMBOL_TARS_ROUTE_KEY = 21, /* TARS_ROUTE_KEY */ + YYSYMBOL_TARS_REQUIRE = 22, /* TARS_REQUIRE */ + YYSYMBOL_TARS_OPTIONAL = 23, /* TARS_OPTIONAL */ + YYSYMBOL_TARS_CONST_INTEGER = 24, /* TARS_CONST_INTEGER */ + YYSYMBOL_TARS_CONST_FLOAT = 25, /* TARS_CONST_FLOAT */ + YYSYMBOL_TARS_FALSE = 26, /* TARS_FALSE */ + YYSYMBOL_TARS_TRUE = 27, /* TARS_TRUE */ + YYSYMBOL_TARS_STRING_LITERAL = 28, /* TARS_STRING_LITERAL */ + YYSYMBOL_TARS_SCOPE_DELIMITER = 29, /* TARS_SCOPE_DELIMITER */ + YYSYMBOL_TARS_CONST = 30, /* TARS_CONST */ + YYSYMBOL_TARS_ENUM = 31, /* TARS_ENUM */ + YYSYMBOL_TARS_UNSIGNED = 32, /* TARS_UNSIGNED */ + YYSYMBOL_BAD_CHAR = 33, /* BAD_CHAR */ + YYSYMBOL_34_ = 34, /* ';' */ + YYSYMBOL_35_ = 35, /* '{' */ + YYSYMBOL_36_ = 36, /* '}' */ + YYSYMBOL_37_ = 37, /* ',' */ + YYSYMBOL_38_ = 38, /* '=' */ + YYSYMBOL_39_ = 39, /* '[' */ + YYSYMBOL_40_ = 40, /* ']' */ + YYSYMBOL_41_ = 41, /* ')' */ + YYSYMBOL_42_ = 42, /* '*' */ + YYSYMBOL_43_ = 43, /* ':' */ + YYSYMBOL_44_ = 44, /* '<' */ + YYSYMBOL_45_ = 45, /* '>' */ + YYSYMBOL_YYACCEPT = 46, /* $accept */ + YYSYMBOL_start = 47, /* start */ + YYSYMBOL_definitions = 48, /* definitions */ + YYSYMBOL_49_1 = 49, /* $@1 */ + YYSYMBOL_50_2 = 50, /* $@2 */ + YYSYMBOL_definition = 51, /* definition */ + YYSYMBOL_enum_def = 52, /* enum_def */ + YYSYMBOL_53_3 = 53, /* @3 */ + YYSYMBOL_enum_id = 54, /* enum_id */ + YYSYMBOL_enumerator_list = 55, /* enumerator_list */ + YYSYMBOL_enumerator = 56, /* enumerator */ + YYSYMBOL_namespace_def = 57, /* namespace_def */ + YYSYMBOL_58_4 = 58, /* @4 */ + YYSYMBOL_key_def = 59, /* key_def */ + YYSYMBOL_60_5 = 60, /* $@5 */ + YYSYMBOL_key_members = 61, /* key_members */ + YYSYMBOL_interface_def = 62, /* interface_def */ + YYSYMBOL_63_6 = 63, /* @6 */ + YYSYMBOL_interface_id = 64, /* interface_id */ + YYSYMBOL_interface_exports = 65, /* interface_exports */ + YYSYMBOL_interface_export = 66, /* interface_export */ + YYSYMBOL_operation = 67, /* operation */ + YYSYMBOL_operation_preamble = 68, /* operation_preamble */ + YYSYMBOL_return_type = 69, /* return_type */ + YYSYMBOL_parameters = 70, /* parameters */ + YYSYMBOL_routekey_qualifier = 71, /* routekey_qualifier */ + YYSYMBOL_out_qualifier = 72, /* out_qualifier */ + YYSYMBOL_struct_def = 73, /* struct_def */ + YYSYMBOL_74_7 = 74, /* @7 */ + YYSYMBOL_struct_id = 75, /* struct_id */ + YYSYMBOL_struct_exports = 76, /* struct_exports */ + YYSYMBOL_data_member = 77, /* data_member */ + YYSYMBOL_struct_type_id = 78, /* struct_type_id */ + YYSYMBOL_const_initializer = 79, /* const_initializer */ + YYSYMBOL_const_def = 80, /* const_def */ + YYSYMBOL_type_id = 81, /* type_id */ + YYSYMBOL_type = 82, /* type */ + YYSYMBOL_type_no = 83, /* type_no */ + YYSYMBOL_vector = 84, /* vector */ + YYSYMBOL_map = 85, /* map */ + YYSYMBOL_scoped_name = 86, /* scoped_name */ + YYSYMBOL_keyword = 87 /* keyword */ +}; +typedef enum yysymbol_kind_t yysymbol_kind_t; -/* Value type. */ -#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED -typedef int YYSTYPE; -# define YYSTYPE_IS_TRIVIAL 1 -# define YYSTYPE_IS_DECLARED 1 -#endif -extern YYSTYPE yylval; -int yyparse (void); +#ifdef short +# undef short +#endif -#endif /* !YY_YY_TARS_TAB_HPP_INCLUDED */ +/* On compilers that do not define __PTRDIFF_MAX__ etc., make sure + and (if available) are included + so that the code can choose integer types of a good width. */ -/* Copy the second part of user declarations. */ +#ifndef __PTRDIFF_MAX__ +# include /* INFRINGES ON USER NAME SPACE */ +# if defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_STDINT_H +# endif +#endif -#line 165 "tars.tab.cpp" /* yacc.c:358 */ +/* Narrow types that promote to a signed type and that can represent a + signed or unsigned integer of at least N bits. In tables they can + save space and decrease cache pressure. Promoting to a signed type + helps avoid bugs in integer arithmetic. */ -#ifdef short -# undef short +#ifdef __INT_LEAST8_MAX__ +typedef __INT_LEAST8_TYPE__ yytype_int8; +#elif defined YY_STDINT_H +typedef int_least8_t yytype_int8; +#else +typedef signed char yytype_int8; #endif -#ifdef YYTYPE_UINT8 -typedef YYTYPE_UINT8 yytype_uint8; +#ifdef __INT_LEAST16_MAX__ +typedef __INT_LEAST16_TYPE__ yytype_int16; +#elif defined YY_STDINT_H +typedef int_least16_t yytype_int16; #else -typedef unsigned char yytype_uint8; +typedef short yytype_int16; #endif -#ifdef YYTYPE_INT8 -typedef YYTYPE_INT8 yytype_int8; -#else -typedef signed char yytype_int8; +/* Work around bug in HP-UX 11.23, which defines these macros + incorrectly for preprocessor constants. This workaround can likely + be removed in 2023, as HPE has promised support for HP-UX 11.23 + (aka HP-UX 11i v2) only through the end of 2022; see Table 2 of + . */ +#ifdef __hpux +# undef UINT_LEAST8_MAX +# undef UINT_LEAST16_MAX +# define UINT_LEAST8_MAX 255 +# define UINT_LEAST16_MAX 65535 #endif -#ifdef YYTYPE_UINT16 -typedef YYTYPE_UINT16 yytype_uint16; +#if defined __UINT_LEAST8_MAX__ && __UINT_LEAST8_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST8_TYPE__ yytype_uint8; +#elif (!defined __UINT_LEAST8_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST8_MAX <= INT_MAX) +typedef uint_least8_t yytype_uint8; +#elif !defined __UINT_LEAST8_MAX__ && UCHAR_MAX <= INT_MAX +typedef unsigned char yytype_uint8; #else -typedef unsigned short int yytype_uint16; +typedef short yytype_uint8; #endif -#ifdef YYTYPE_INT16 -typedef YYTYPE_INT16 yytype_int16; +#if defined __UINT_LEAST16_MAX__ && __UINT_LEAST16_MAX__ <= __INT_MAX__ +typedef __UINT_LEAST16_TYPE__ yytype_uint16; +#elif (!defined __UINT_LEAST16_MAX__ && defined YY_STDINT_H \ + && UINT_LEAST16_MAX <= INT_MAX) +typedef uint_least16_t yytype_uint16; +#elif !defined __UINT_LEAST16_MAX__ && USHRT_MAX <= INT_MAX +typedef unsigned short yytype_uint16; #else -typedef short int yytype_int16; +typedef int yytype_uint16; +#endif + +#ifndef YYPTRDIFF_T +# if defined __PTRDIFF_TYPE__ && defined __PTRDIFF_MAX__ +# define YYPTRDIFF_T __PTRDIFF_TYPE__ +# define YYPTRDIFF_MAXIMUM __PTRDIFF_MAX__ +# elif defined PTRDIFF_MAX +# ifndef ptrdiff_t +# include /* INFRINGES ON USER NAME SPACE */ +# endif +# define YYPTRDIFF_T ptrdiff_t +# define YYPTRDIFF_MAXIMUM PTRDIFF_MAX +# else +# define YYPTRDIFF_T long +# define YYPTRDIFF_MAXIMUM LONG_MAX +# endif #endif #ifndef YYSIZE_T @@ -196,15 +295,28 @@ typedef short int yytype_int16; # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif ! defined YYSIZE_T +# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else -# define YYSIZE_T unsigned int +# define YYSIZE_T unsigned # endif #endif -#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) +#define YYSIZE_MAXIMUM \ + YY_CAST (YYPTRDIFF_T, \ + (YYPTRDIFF_MAXIMUM < YY_CAST (YYSIZE_T, -1) \ + ? YYPTRDIFF_MAXIMUM \ + : YY_CAST (YYSIZE_T, -1))) + +#define YYSIZEOF(X) YY_CAST (YYPTRDIFF_T, sizeof (X)) + + +/* Stored state numbers (used for stacks). */ +typedef yytype_uint8 yy_state_t; + +/* State numbers in computations. */ +typedef int yy_state_fast_t; #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS @@ -218,47 +330,37 @@ typedef short int yytype_int16; # endif #endif -#ifndef YY_ATTRIBUTE -# if (defined __GNUC__ \ - && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ - || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C -# define YY_ATTRIBUTE(Spec) __attribute__(Spec) -# else -# define YY_ATTRIBUTE(Spec) /* empty */ -# endif -#endif #ifndef YY_ATTRIBUTE_PURE -# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +# else +# define YY_ATTRIBUTE_PURE +# endif #endif #ifndef YY_ATTRIBUTE_UNUSED -# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) -#endif - -#if !defined _Noreturn \ - && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) -# if defined _MSC_VER && 1200 <= _MSC_VER -# define _Noreturn __declspec (noreturn) +# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) +# define YY_ATTRIBUTE_UNUSED __attribute__ ((__unused__)) # else -# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) +# define YY_ATTRIBUTE_UNUSED # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(E) ((void) (E)) +# define YY_USE(E) ((void) (E)) #else -# define YYUSE(E) /* empty */ +# define YY_USE(E) /* empty */ #endif -#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ /* Suppress an incorrect diagnostic about yylval being uninitialized. */ -# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ - _Pragma ("GCC diagnostic push") \ - _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"") \ _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") -# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ _Pragma ("GCC diagnostic pop") #else # define YY_INITIAL_VALUE(Value) Value @@ -271,8 +373,22 @@ typedef short int yytype_int16; # define YY_INITIAL_VALUE(Value) /* Nothing. */ #endif +#if defined __cplusplus && defined __GNUC__ && ! defined __ICC && 6 <= __GNUC__ +# define YY_IGNORE_USELESS_CAST_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuseless-cast\"") +# define YY_IGNORE_USELESS_CAST_END \ + _Pragma ("GCC diagnostic pop") +#endif +#ifndef YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_BEGIN +# define YY_IGNORE_USELESS_CAST_END +#endif + -#if ! defined yyoverflow || YYERROR_VERBOSE +#define YY_ASSERT(E) ((void) (0 && (E))) + +#if !defined yyoverflow /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -337,8 +453,7 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif -#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ - +#endif /* !defined yyoverflow */ #if (! defined yyoverflow \ && (! defined __cplusplus \ @@ -347,17 +462,17 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ /* A type that is properly aligned for any stack member. */ union yyalloc { - yytype_int16 yyss_alloc; + yy_state_t yyss_alloc; YYSTYPE yyvs_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) +# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ - ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) # define YYCOPY_NEEDED 1 @@ -370,11 +485,11 @@ union yyalloc # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ - YYSIZE_T yynewbytes; \ + YYPTRDIFF_T yynewbytes; \ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ + yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / YYSIZEOF (*yyptr); \ } \ while (0) @@ -386,12 +501,12 @@ union yyalloc # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) + __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) # else # define YYCOPY(Dst, Src, Count) \ do \ { \ - YYSIZE_T yyi; \ + YYPTRDIFF_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (Dst)[yyi] = (Src)[yyi]; \ } \ @@ -414,17 +529,20 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES 199 -/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned - by yylex, with out-of-bounds checking. */ -#define YYUNDEFTOK 2 +/* YYMAXUTOK -- Last valid token kind. */ #define YYMAXUTOK 288 -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM + as returned by yylex, with out-of-bounds checking. */ +#define YYTRANSLATE(YYX) \ + (0 <= (YYX) && (YYX) <= YYMAXUTOK \ + ? YY_CAST (yysymbol_kind_t, yytranslate[YYX]) \ + : YYSYMBOL_YYUNDEF) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM - as returned by yylex, without out-of-bounds checking. */ -static const yytype_uint8 yytranslate[] = + as returned by yylex. */ +static const yytype_int8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -459,7 +577,7 @@ static const yytype_uint8 yytranslate[] = #if YYDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_uint16 yyrline[] = +static const yytype_int16 yyrline[] = { 0, 68, 68, 75, 74, 79, 78, 83, 88, 95, 99, 103, 107, 110, 114, 124, 123, 146, 159, 170, @@ -478,35 +596,48 @@ static const yytype_uint16 yyrline[] = }; #endif -#if YYDEBUG || YYERROR_VERBOSE || 0 +/** Accessing symbol of state STATE. */ +#define YY_ACCESSING_SYMBOL(State) YY_CAST (yysymbol_kind_t, yystos[State]) + +#if YYDEBUG || 0 +/* The user-facing name of the symbol whose (internal) number is + YYSYMBOL. No bounds checking. */ +static const char *yysymbol_name (yysymbol_kind_t yysymbol) YY_ATTRIBUTE_UNUSED; + /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "$end", "error", "$undefined", "TARS_VOID", "TARS_STRUCT", "TARS_BOOL", - "TARS_BYTE", "TARS_SHORT", "TARS_INT", "TARS_DOUBLE", "TARS_FLOAT", - "TARS_LONG", "TARS_STRING", "TARS_VECTOR", "TARS_MAP", "TARS_NAMESPACE", - "TARS_INTERFACE", "TARS_IDENTIFIER", "TARS_OUT", "TARS_OP", "TARS_KEY", - "TARS_ROUTE_KEY", "TARS_REQUIRE", "TARS_OPTIONAL", "TARS_CONST_INTEGER", - "TARS_CONST_FLOAT", "TARS_FALSE", "TARS_TRUE", "TARS_STRING_LITERAL", - "TARS_SCOPE_DELIMITER", "TARS_CONST", "TARS_ENUM", "TARS_UNSIGNED", - "BAD_CHAR", "';'", "'{'", "'}'", "','", "'='", "'['", "']'", "')'", - "'*'", "':'", "'<'", "'>'", "$accept", "start", "definitions", "$@1", - "$@2", "definition", "enum_def", "@3", "enum_id", "enumerator_list", - "enumerator", "namespace_def", "@4", "key_def", "$@5", "key_members", - "interface_def", "@6", "interface_id", "interface_exports", - "interface_export", "operation", "operation_preamble", "return_type", - "parameters", "routekey_qualifier", "out_qualifier", "struct_def", "@7", - "struct_id", "struct_exports", "data_member", "struct_type_id", - "const_initializer", "const_def", "type_id", "type", "type_no", "vector", - "map", "scoped_name", "keyword", YY_NULLPTR + "\"end of file\"", "error", "\"invalid token\"", "TARS_VOID", + "TARS_STRUCT", "TARS_BOOL", "TARS_BYTE", "TARS_SHORT", "TARS_INT", + "TARS_DOUBLE", "TARS_FLOAT", "TARS_LONG", "TARS_STRING", "TARS_VECTOR", + "TARS_MAP", "TARS_NAMESPACE", "TARS_INTERFACE", "TARS_IDENTIFIER", + "TARS_OUT", "TARS_OP", "TARS_KEY", "TARS_ROUTE_KEY", "TARS_REQUIRE", + "TARS_OPTIONAL", "TARS_CONST_INTEGER", "TARS_CONST_FLOAT", "TARS_FALSE", + "TARS_TRUE", "TARS_STRING_LITERAL", "TARS_SCOPE_DELIMITER", "TARS_CONST", + "TARS_ENUM", "TARS_UNSIGNED", "BAD_CHAR", "';'", "'{'", "'}'", "','", + "'='", "'['", "']'", "')'", "'*'", "':'", "'<'", "'>'", "$accept", + "start", "definitions", "$@1", "$@2", "definition", "enum_def", "@3", + "enum_id", "enumerator_list", "enumerator", "namespace_def", "@4", + "key_def", "$@5", "key_members", "interface_def", "@6", "interface_id", + "interface_exports", "interface_export", "operation", + "operation_preamble", "return_type", "parameters", "routekey_qualifier", + "out_qualifier", "struct_def", "@7", "struct_id", "struct_exports", + "data_member", "struct_type_id", "const_initializer", "const_def", + "type_id", "type", "type_no", "vector", "map", "scoped_name", "keyword", YY_NULLPTR }; + +static const char * +yysymbol_name (yysymbol_kind_t yysymbol) +{ + return yytname[yysymbol]; +} #endif -# ifdef YYPRINT +#ifdef YYPRINT /* YYTOKNUM[NUM] -- (External) token number corresponding to the (internal) symbol number NUM (which must be that of a token). */ -static const yytype_uint16 yytoknum[] = +static const yytype_int16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, @@ -514,16 +645,16 @@ static const yytype_uint16 yytoknum[] = 285, 286, 287, 288, 59, 123, 125, 44, 61, 91, 93, 41, 42, 58, 60, 62 }; -# endif +#endif -#define YYPACT_NINF -146 +#define YYPACT_NINF (-146) -#define yypact_value_is_default(Yystate) \ - (!!((Yystate) == (-146))) +#define yypact_value_is_default(Yyn) \ + ((Yyn) == YYPACT_NINF) -#define YYTABLE_NINF -113 +#define YYTABLE_NINF (-113) -#define yytable_value_is_error(Yytable_value) \ +#define yytable_value_is_error(Yyn) \ 0 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing @@ -590,9 +721,9 @@ static const yytype_int16 yypgoto[] = }; /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_int16 yydefgoto[] = +static const yytype_uint8 yydefgoto[] = { - -1, 8, 9, 76, 80, 10, 11, 77, 12, 123, + 0, 8, 9, 76, 80, 10, 11, 77, 12, 123, 124, 13, 81, 14, 142, 171, 15, 78, 16, 128, 129, 130, 131, 132, 157, 158, 159, 17, 79, 18, 137, 138, 139, 113, 19, 140, 68, 69, 70, 71, @@ -726,7 +857,7 @@ static const yytype_int16 yycheck[] = /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ -static const yytype_uint8 yystos[] = +static const yytype_int8 yystos[] = { 0, 1, 4, 15, 16, 20, 30, 31, 47, 48, 51, 52, 54, 57, 59, 62, 64, 73, 75, 80, @@ -751,7 +882,7 @@ static const yytype_uint8 yystos[] = }; /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_uint8 yyr1[] = +static const yytype_int8 yyr1[] = { 0, 46, 47, 49, 48, 50, 48, 48, 48, 51, 51, 51, 51, 51, 51, 53, 52, 54, 54, 55, @@ -770,7 +901,7 @@ static const yytype_uint8 yyr1[] = }; /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_uint8 yyr2[] = +static const yytype_int8 yyr2[] = { 0, 2, 1, 0, 4, 0, 4, 1, 0, 1, 1, 1, 1, 1, 1, 0, 5, 2, 2, 3, @@ -789,10 +920,10 @@ static const yytype_uint8 yyr2[] = }; +enum { YYENOMEM = -2 }; + #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab @@ -801,27 +932,26 @@ static const yytype_uint8 yyr2[] = #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (yylen); \ - yystate = *yyssp; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror (YY_("syntax error: cannot back up")); \ - YYERROR; \ - } \ -while (0) - -/* Error token number */ -#define YYTERROR 1 -#define YYERRCODE 256 - +#define YYBACKUP(Token, Value) \ + do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ + while (0) + +/* Backward compatibility with an undocumented macro. + Use YYerror or YYUNDEF. */ +#define YYERRCODE YYUNDEF /* Enable debugging if requested. */ @@ -839,54 +969,58 @@ do { \ } while (0) /* This macro is provided for backward compatibility. */ -#ifndef YY_LOCATION_PRINT -# define YY_LOCATION_PRINT(File, Loc) ((void) 0) -#endif +# ifndef YY_LOCATION_PRINT +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value); \ + Kind, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) -/*----------------------------------------. -| Print this symbol's value on YYOUTPUT. | -`----------------------------------------*/ +/*-----------------------------------. +| Print this symbol's value on YYO. | +`-----------------------------------*/ static void -yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +yy_symbol_value_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) { - FILE *yyo = yyoutput; - YYUSE (yyo); + FILE *yyoutput = yyo; + YY_USE (yyoutput); if (!yyvaluep) return; # ifdef YYPRINT - if (yytype < YYNTOKENS) - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); + if (yykind < YYNTOKENS) + YYPRINT (yyo, yytoknum[yykind], *yyvaluep); # endif - YYUSE (yytype); + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + YY_USE (yykind); + YY_IGNORE_MAYBE_UNINITIALIZED_END } -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ +/*---------------------------. +| Print this symbol on YYO. | +`---------------------------*/ static void -yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) +yy_symbol_print (FILE *yyo, + yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) { - YYFPRINTF (yyoutput, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + YYFPRINTF (yyo, "%s %s (", + yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); - yy_symbol_value_print (yyoutput, yytype, yyvaluep); - YYFPRINTF (yyoutput, ")"); + yy_symbol_value_print (yyo, yykind, yyvaluep); + YYFPRINTF (yyo, ")"); } /*------------------------------------------------------------------. @@ -895,7 +1029,7 @@ yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) `------------------------------------------------------------------*/ static void -yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -918,21 +1052,21 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) +yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, + int yyrule) { - unsigned long int yylno = yyrline[yyrule]; + int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &(yyvsp[(yyi + 1) - (yynrhs)]) - ); + YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), + &yyvsp[(yyi + 1) - (yynrhs)]); YYFPRINTF (stderr, "\n"); } } @@ -947,8 +1081,8 @@ do { \ multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YYDPRINTF(Args) ((void) 0) +# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ @@ -971,249 +1105,30 @@ int yydebug; #endif -#if YYERROR_VERBOSE -# ifndef yystrlen -# if defined __GLIBC__ && defined _STRING_H -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -static YYSIZE_T -yystrlen (const char *yystr) -{ - YYSIZE_T yylen; - for (yylen = 0; yystr[yylen]; yylen++) - continue; - return yylen; -} -# endif -# endif -# ifndef yystpcpy -# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -static char * -yystpcpy (char *yydest, const char *yysrc) -{ - char *yyd = yydest; - const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - return yyd - 1; -} -# endif -# endif - -# ifndef yytnamerr -/* Copy to YYRES the contents of YYSTR after stripping away unnecessary - quotes and backslashes, so that it's suitable for yyerror. The - heuristic is that double-quoting is unnecessary unless the string - contains an apostrophe, a comma, or backslash (other than - backslash-backslash). YYSTR is taken from yytname. If YYRES is - null, do not copy; instead, return the length of what the result - would have been. */ -static YYSIZE_T -yytnamerr (char *yyres, const char *yystr) -{ - if (*yystr == '"') - { - YYSIZE_T yyn = 0; - char const *yyp = yystr; - - for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } - do_not_strip_quotes: ; - } - - if (! yyres) - return yystrlen (yystr); - - return yystpcpy (yyres, yystr) - yyres; -} -# endif - -/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message - about the unexpected token YYTOKEN for the state stack whose top is - YYSSP. - - Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is - not large enough to hold the message. In that case, also set - *YYMSG_ALLOC to the required number of bytes. Return 2 if the - required number of bytes is too large to store. */ -static int -yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) -{ - YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); - YYSIZE_T yysize = yysize0; - enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; - /* Internationalized format string. */ - const char *yyformat = YY_NULLPTR; - /* Arguments of yyformat. */ - char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; - /* Number of reported tokens (one for the "unexpected", one per - "expected"). */ - int yycount = 0; - - /* There are many possibilities here to consider: - - If this state is a consistent state with a default action, then - the only way this function was invoked is if the default action - is an error action. In that case, don't check for expected - tokens because there are none. - - The only way there can be no lookahead present (in yychar) is if - this state is a consistent state with a default action. Thus, - detecting the absence of a lookahead is sufficient to determine - that there is no unexpected or expected token to report. In that - case, just report a simple "syntax error". - - Don't assume there isn't a lookahead just because this state is a - consistent state with a default action. There might have been a - previous inconsistent state, consistent state with a non-default - action, or user semantic action that manipulated yychar. - - Of course, the expected token list depends on states to have - correct lookahead information, and it depends on the parser not - to perform extra reductions after fetching a lookahead from the - scanner and before detecting a syntax error. Thus, state merging - (from LALR or IELR) and default reductions corrupt the expected - token list. However, the list is correct for canonical LR with - one exception: it will still contain any token that will not be - accepted due to an error action in a later state. - */ - if (yytoken != YYEMPTY) - { - int yyn = yypact[*yyssp]; - yyarg[yycount++] = yytname[yytoken]; - if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } - } - } - - switch (yycount) - { -# define YYCASE_(N, S) \ - case N: \ - yyformat = S; \ - break - YYCASE_(0, YY_("syntax error")); - YYCASE_(1, YY_("syntax error, unexpected %s")); - YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); - YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); - YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); - YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); -# undef YYCASE_ - } - - { - YYSIZE_T yysize1 = yysize + yystrlen (yyformat); - if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - - if (*yymsg_alloc < yysize) - { - *yymsg_alloc = 2 * yysize; - if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; - return 1; - } - - /* Avoid sprintf, as that infringes on the user's name space. - Don't have undefined behavior even if the translation - produced a string with the wrong number of "%s"s. */ - { - char *yyp = *yymsg; - int yyi = 0; - while ((*yyp = *yyformat) != '\0') - if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } - else - { - yyp++; - yyformat++; - } - } - return 0; -} -#endif /* YYERROR_VERBOSE */ /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ static void -yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) +yydestruct (const char *yymsg, + yysymbol_kind_t yykind, YYSTYPE *yyvaluep) { - YYUSE (yyvaluep); + YY_USE (yyvaluep); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YYUSE (yytype); + YY_USE (yykind); YY_IGNORE_MAYBE_UNINITIALIZED_END } - - -/* The lookahead symbol. */ +/* Lookahead token kind. */ int yychar; /* The semantic value of the lookahead symbol. */ @@ -1222,6 +1137,8 @@ YYSTYPE yylval; int yynerrs; + + /*----------. | yyparse. | `----------*/ @@ -1229,43 +1146,36 @@ int yynerrs; int yyparse (void) { - int yystate; + yy_state_fast_t yystate = 0; /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; + int yyerrstatus = 0; - /* The stacks and their tools: - 'yyss': related to states. - 'yyvs': related to semantic values. - - Refer to the stacks through separate pointers, to allow yyoverflow + /* Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ - /* The state stack. */ - yytype_int16 yyssa[YYINITDEPTH]; - yytype_int16 *yyss; - yytype_int16 *yyssp; + /* Their size. */ + YYPTRDIFF_T yystacksize = YYINITDEPTH; - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs; - YYSTYPE *yyvsp; + /* The state stack: array, bottom, top. */ + yy_state_t yyssa[YYINITDEPTH]; + yy_state_t *yyss = yyssa; + yy_state_t *yyssp = yyss; - YYSIZE_T yystacksize; + /* The semantic value stack: array, bottom, top. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + YYSTYPE *yyvsp = yyvs; int yyn; + /* The return value of yyparse. */ int yyresult; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; + /* Lookahead symbol kind. */ + yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; -#if YYERROR_VERBOSE - /* Buffer for error messages, and its allocated size. */ - char yymsgbuf[128]; - char *yymsg = yymsgbuf; - YYSIZE_T yymsg_alloc = sizeof yymsgbuf; -#endif + #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) @@ -1273,58 +1183,60 @@ yyparse (void) Keep to zero when no symbol should be popped. */ int yylen = 0; - yyssp = yyss = yyssa; - yyvsp = yyvs = yyvsa; - yystacksize = YYINITDEPTH; - YYDPRINTF ((stderr, "Starting parse\n")); - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ goto yysetstate; + /*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | +| yynewstate -- push a new state, which is found in yystate. | `------------------------------------------------------------*/ - yynewstate: +yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; - yysetstate: - *yyssp = yystate; + +/*--------------------------------------------------------------------. +| yysetstate -- set current state (the top of the stack) to yystate. | +`--------------------------------------------------------------------*/ +yysetstate: + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + YY_ASSERT (0 <= yystate && yystate < YYNSTATES); + YY_IGNORE_USELESS_CAST_BEGIN + *yyssp = YY_CAST (yy_state_t, yystate); + YY_IGNORE_USELESS_CAST_END + YY_STACK_PRINT (yyss, yyssp); if (yyss + yystacksize - 1 <= yyssp) +#if !defined yyoverflow && !defined YYSTACK_RELOCATE + goto yyexhaustedlab; +#else { /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; + YYPTRDIFF_T yysize = yyssp - yyss + 1; -#ifdef yyoverflow +# if defined yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ + yy_state_t *yyss1 = yyss; YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), + &yyss1, yysize * YYSIZEOF (*yyssp), + &yyvs1, yysize * YYSIZEOF (*yyvsp), &yystacksize); - yyss = yyss1; yyvs = yyvs1; } -#else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyexhaustedlab; -# else +# else /* defined YYSTACK_RELOCATE */ /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; @@ -1333,9 +1245,10 @@ yyparse (void) yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; + yy_state_t *yyss1 = yyss; union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + YY_CAST (union yyalloc *, + YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); @@ -1345,30 +1258,30 @@ yyparse (void) YYSTACK_FREE (yyss1); } # endif -#endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); + YY_IGNORE_USELESS_CAST_BEGIN + YYDPRINTF ((stderr, "Stack size increased to %ld\n", + YY_CAST (long, yystacksize))); + YY_IGNORE_USELESS_CAST_END if (yyss + yystacksize - 1 <= yyssp) YYABORT; } - - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); +#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ if (yystate == YYFINAL) YYACCEPT; goto yybackup; + /*-----------. | yybackup. | `-----------*/ yybackup: - /* Do appropriate processing given the current state. Read a lookahead token if we need one and don't already have one. */ @@ -1379,18 +1292,29 @@ yyparse (void) /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ if (yychar == YYEMPTY) { - YYDPRINTF ((stderr, "Reading a token: ")); + YYDPRINTF ((stderr, "Reading a token\n")); yychar = yylex (); } if (yychar <= YYEOF) { - yychar = yytoken = YYEOF; + yychar = YYEOF; + yytoken = YYSYMBOL_YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } + else if (yychar == YYerror) + { + /* The scanner already issued an error message, process directly + to error recovery. But do not keep the error token as + lookahead, it is too special and may lead us to an endless + loop in error recovery. */ + yychar = YYUNDEF; + yytoken = YYSYMBOL_YYerror; + goto yyerrlab1; + } else { yytoken = YYTRANSLATE (yychar); @@ -1418,15 +1342,13 @@ yyparse (void) /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); - - /* Discard the shifted token. */ - yychar = YYEMPTY; - yystate = yyn; YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; YY_IGNORE_MAYBE_UNINITIALIZED_END + /* Discard the shifted token. */ + yychar = YYEMPTY; goto yynewstate; @@ -1441,7 +1363,7 @@ yyparse (void) /*-----------------------------. -| yyreduce -- Do a reduction. | +| yyreduce -- do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ @@ -1461,238 +1383,238 @@ yyparse (void) YY_REDUCE_PRINT (yyn); switch (yyn) { - case 3: -#line 75 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 3: /* $@1: %empty */ +#line 75 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1469 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1391 "tars.tab.cpp" break; - case 5: -#line 79 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 5: /* $@2: %empty */ +#line 79 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ yyerrok; } -#line 1477 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1399 "tars.tab.cpp" break; - case 7: -#line 84 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 7: /* definitions: definition */ +#line 84 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("`;' missing after definition"); } -#line 1485 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1407 "tars.tab.cpp" break; - case 8: -#line 88 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 8: /* definitions: %empty */ +#line 88 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1492 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1414 "tars.tab.cpp" break; - case 9: -#line 96 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - assert((yyvsp[0]) == 0 || NamespacePtr::dynamicCast((yyvsp[0]))); + case 9: /* definition: namespace_def */ +#line 96 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + assert(yyvsp[0] == 0 || NamespacePtr::dynamicCast(yyvsp[0])); } -#line 1500 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1422 "tars.tab.cpp" break; - case 10: -#line 100 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - assert((yyvsp[0]) == 0 || InterfacePtr::dynamicCast((yyvsp[0]))); + case 10: /* definition: interface_def */ +#line 100 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + assert(yyvsp[0] == 0 || InterfacePtr::dynamicCast(yyvsp[0])); } -#line 1508 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1430 "tars.tab.cpp" break; - case 11: -#line 104 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - assert((yyvsp[0]) == 0 || StructPtr::dynamicCast((yyvsp[0]))); + case 11: /* definition: struct_def */ +#line 104 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + assert(yyvsp[0] == 0 || StructPtr::dynamicCast(yyvsp[0])); } -#line 1516 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1438 "tars.tab.cpp" break; - case 12: -#line 108 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 12: /* definition: key_def */ +#line 108 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1523 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1445 "tars.tab.cpp" break; - case 13: -#line 111 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - assert((yyvsp[0]) == 0 || EnumPtr::dynamicCast((yyvsp[0]))); + case 13: /* definition: enum_def */ +#line 111 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + assert(yyvsp[0] == 0 || EnumPtr::dynamicCast(yyvsp[0])); } -#line 1531 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1453 "tars.tab.cpp" break; - case 14: -#line 115 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - assert((yyvsp[0]) == 0 || ConstPtr::dynamicCast((yyvsp[0]))); + case 14: /* definition: const_def */ +#line 115 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + assert(yyvsp[0] == 0 || ConstPtr::dynamicCast(yyvsp[0])); } -#line 1539 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1461 "tars.tab.cpp" break; - case 15: -#line 124 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = (yyvsp[0]); + case 15: /* @3: %empty */ +#line 124 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = yyvsp[0]; } -#line 1547 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1469 "tars.tab.cpp" break; - case 16: -#line 128 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - if((yyvsp[-2])) + case 16: /* enum_def: enum_id @3 '{' enumerator_list '}' */ +#line 128 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + if(yyvsp[-2]) { g_parse->popContainer(); - (yyval) = (yyvsp[-2]); + yyval = yyvsp[-2]; } else { - (yyval) = 0; + yyval = 0; } - (yyval) = (yyvsp[-3]); + yyval = yyvsp[-3]; } -#line 1565 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1487 "tars.tab.cpp" break; - case 17: -#line 147 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 17: /* enum_id: TARS_ENUM TARS_IDENTIFIER */ +#line 147 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ NamespacePtr c = NamespacePtr::dynamicCast(g_parse->currentContainer()); if(!c) { g_parse->error("enum must define in namespace"); } - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); EnumPtr e = c->createEnum(ident->v); g_parse->pushContainer(e); - (yyval) = e; + yyval = e; } -#line 1582 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1504 "tars.tab.cpp" break; - case 18: -#line 160 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 18: /* enum_id: TARS_ENUM keyword */ +#line 160 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); g_parse->error("keyword `" + ident->v + "' cannot be used as enumeration name"); - (yyval) = (yyvsp[0]); + yyval = yyvsp[0]; } -#line 1592 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1514 "tars.tab.cpp" break; - case 19: -#line 171 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = (yyvsp[-1]); + case 19: /* enumerator_list: enumerator ',' enumerator_list */ +#line 171 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = yyvsp[-1]; } -#line 1600 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1522 "tars.tab.cpp" break; - case 20: -#line 175 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 20: /* enumerator_list: enumerator */ +#line 175 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1607 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1529 "tars.tab.cpp" break; - case 21: -#line 183 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 21: /* enumerator: TARS_IDENTIFIER */ +#line 183 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ TypePtr type = TypePtr::dynamicCast(g_parse->createBuiltin(Builtin::KindLong)); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); TypeIdPtr tPtr = new TypeId(type, ident->v); tPtr->disableDefault(); EnumPtr e = EnumPtr::dynamicCast(g_parse->currentContainer()); assert(e); e->addMember(tPtr); - (yyval) = e; + yyval = e; } -#line 1622 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1544 "tars.tab.cpp" break; - case 22: -#line 194 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 22: /* enumerator: keyword */ +#line 194 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); g_parse->error("keyword `" + ident->v + "' cannot be used as enumerator"); } -#line 1631 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1553 "tars.tab.cpp" break; - case 23: -#line 199 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 23: /* enumerator: TARS_IDENTIFIER '=' const_initializer */ +#line 199 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ TypePtr type = TypePtr::dynamicCast(g_parse->createBuiltin(Builtin::KindLong)); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[-2])); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-2]); TypeIdPtr tPtr = new TypeId(type, ident->v); - ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast((yyvsp[0])); + ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast(yyvsp[0]); g_parse->checkConstValue(tPtr, sPtr->t); tPtr->setDefault(sPtr->v); EnumPtr e = EnumPtr::dynamicCast(g_parse->currentContainer()); assert(e); e->addMember(tPtr); - (yyval) = e; + yyval = e; } -#line 1648 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1570 "tars.tab.cpp" break; - case 24: -#line 212 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 24: /* enumerator: %empty */ +#line 212 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1655 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1577 "tars.tab.cpp" break; - case 25: -#line 220 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 25: /* @4: %empty */ +#line 220 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); ContainerPtr c = g_parse->currentContainer(); NamespacePtr n = c->createNamespace(ident->v); if(n) { g_parse->pushContainer(n); - (yyval) = GrammarBasePtr::dynamicCast(n); + yyval = GrammarBasePtr::dynamicCast(n); } else { - (yyval) = 0; + yyval = 0; } } -#line 1674 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1596 "tars.tab.cpp" break; - case 26: -#line 235 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - if((yyvsp[-3])) + case 26: /* namespace_def: TARS_NAMESPACE TARS_IDENTIFIER @4 '{' definitions '}' */ +#line 235 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + if(yyvsp[-3]) { g_parse->popContainer(); - (yyval) = (yyvsp[-3]); + yyval = yyvsp[-3]; } else { - (yyval) = 0; + yyval = 0; } } -#line 1690 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1612 "tars.tab.cpp" break; - case 27: -#line 253 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[-1])); + case 27: /* $@5: %empty */ +#line 253 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-1]); StructPtr sp = StructPtr::dynamicCast(g_parse->findUserType(ident->v)); if(!sp) { @@ -1701,20 +1623,20 @@ yyparse (void) g_parse->setKeyStruct(sp); } -#line 1705 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1627 "tars.tab.cpp" break; - case 28: -#line 264 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 28: /* key_def: TARS_KEY '[' scoped_name ',' $@5 key_members ']' */ +#line 264 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1712 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1634 "tars.tab.cpp" break; - case 29: -#line 272 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 29: /* key_members: TARS_IDENTIFIER */ +#line 272 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); StructPtr np = g_parse->getKeyStruct(); if(np) { @@ -1722,16 +1644,16 @@ yyparse (void) } else { - (yyval) = 0; + yyval = 0; } } -#line 1729 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1651 "tars.tab.cpp" break; - case 30: -#line 285 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 30: /* key_members: key_members ',' TARS_IDENTIFIER */ +#line 285 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); StructPtr np = g_parse->getKeyStruct(); if(np) { @@ -1739,16 +1661,16 @@ yyparse (void) } else { - (yyval) = 0; + yyval = 0; } } -#line 1746 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1668 "tars.tab.cpp" break; - case 31: -#line 304 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 31: /* @6: %empty */ +#line 304 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); NamespacePtr c = NamespacePtr::dynamicCast(g_parse->currentContainer()); @@ -1756,100 +1678,100 @@ yyparse (void) if(cl) { g_parse->pushContainer(cl); - (yyval) = GrammarBasePtr::dynamicCast(cl); + yyval = GrammarBasePtr::dynamicCast(cl); } else { - (yyval) = 0; + yyval = 0; } } -#line 1767 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1689 "tars.tab.cpp" break; - case 32: -#line 321 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - if((yyvsp[-3])) + case 32: /* interface_def: interface_id @6 '{' interface_exports '}' */ +#line 321 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + if(yyvsp[-3]) { g_parse->popContainer(); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-3])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[-3]); } else { - (yyval) = 0; + yyval = 0; } } -#line 1783 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1705 "tars.tab.cpp" break; - case 33: -#line 338 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = (yyvsp[0]); + case 33: /* interface_id: TARS_INTERFACE TARS_IDENTIFIER */ +#line 338 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = yyvsp[0]; } -#line 1791 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1713 "tars.tab.cpp" break; - case 34: -#line 342 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 34: /* interface_id: TARS_INTERFACE keyword */ +#line 342 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); g_parse->error("keyword `" + ident->v + "' cannot be used as interface name"); - (yyval) = (yyvsp[0]); + yyval = yyvsp[0]; } -#line 1801 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1723 "tars.tab.cpp" break; - case 35: -#line 353 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 35: /* interface_exports: interface_export ';' interface_exports */ +#line 353 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1808 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1730 "tars.tab.cpp" break; - case 36: -#line 356 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 36: /* interface_exports: error ';' interface_exports */ +#line 356 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1815 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1737 "tars.tab.cpp" break; - case 37: -#line 359 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 37: /* interface_exports: interface_export */ +#line 359 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("`;' missing after definition"); } -#line 1823 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1745 "tars.tab.cpp" break; - case 38: -#line 363 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 38: /* interface_exports: %empty */ +#line 363 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1830 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1752 "tars.tab.cpp" break; - case 40: -#line 377 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - if((yyvsp[-2])) + case 40: /* operation: operation_preamble parameters ')' */ +#line 377 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + if(yyvsp[-2]) { g_parse->popContainer(); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-2])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[-2]); } else { - (yyval) = 0; + yyval = 0; } } -#line 1846 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1768 "tars.tab.cpp" break; - case 41: -#line 394 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypePtr returnType = TypePtr::dynamicCast((yyvsp[-1])); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 41: /* operation_preamble: return_type TARS_OP */ +#line 394 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypePtr returnType = TypePtr::dynamicCast(yyvsp[-1]); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); string name = ident->v; InterfacePtr cl = InterfacePtr::dynamicCast(g_parse->currentContainer()); if(cl) @@ -1858,40 +1780,40 @@ yyparse (void) if(op) { g_parse->pushContainer(op); - (yyval) = GrammarBasePtr::dynamicCast(op); + yyval = GrammarBasePtr::dynamicCast(op); } else { - (yyval) = 0; + yyval = 0; } } else { - (yyval) = 0; + yyval = 0; } } -#line 1874 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1796 "tars.tab.cpp" break; - case 43: -#line 424 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = 0; + case 43: /* return_type: TARS_VOID */ +#line 424 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = 0; } -#line 1882 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1804 "tars.tab.cpp" break; - case 44: -#line 434 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 44: /* parameters: %empty */ +#line 434 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 1889 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1811 "tars.tab.cpp" break; - case 45: -#line 437 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 45: /* parameters: type_id */ +#line 437 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1900,13 +1822,13 @@ yyparse (void) op->createParamDecl(tsp, false, false); } } -#line 1904 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1826 "tars.tab.cpp" break; - case 46: -#line 448 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 46: /* parameters: parameters ',' type_id */ +#line 448 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1915,14 +1837,14 @@ yyparse (void) op->createParamDecl(tsp, false, false); } } -#line 1919 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1841 "tars.tab.cpp" break; - case 47: -#line 459 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast((yyvsp[-1])); - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 47: /* parameters: out_qualifier type_id */ +#line 459 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1931,14 +1853,14 @@ yyparse (void) op->createParamDecl(tsp, isOutParam->v, false); } } -#line 1935 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1857 "tars.tab.cpp" break; - case 48: -#line 471 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast((yyvsp[-1])); - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 48: /* parameters: parameters ',' out_qualifier type_id */ +#line 471 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1947,14 +1869,14 @@ yyparse (void) op->createParamDecl(tsp, isOutParam->v, false); } } -#line 1951 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1873 "tars.tab.cpp" break; - case 49: -#line 483 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast((yyvsp[-1])); - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 49: /* parameters: routekey_qualifier type_id */ +#line 483 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1963,14 +1885,14 @@ yyparse (void) op->createParamDecl(tsp, false, isRouteKeyParam->v); } } -#line 1967 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1889 "tars.tab.cpp" break; - case 50: -#line 495 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast((yyvsp[-1])); - TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); + case 50: /* parameters: parameters ',' routekey_qualifier type_id */ +#line 495 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); + TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1979,49 +1901,49 @@ yyparse (void) op->createParamDecl(tsp, false, isRouteKeyParam->v); } } -#line 1983 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1905 "tars.tab.cpp" break; - case 51: -#line 507 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 51: /* parameters: out_qualifier */ +#line 507 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("'out' must be defined with a type"); } -#line 1991 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1913 "tars.tab.cpp" break; - case 52: -#line 511 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 52: /* parameters: routekey_qualifier */ +#line 511 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("'routekey' must be defined with a type"); } -#line 1999 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1921 "tars.tab.cpp" break; - case 53: -#line 520 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 53: /* routekey_qualifier: TARS_ROUTE_KEY */ +#line 520 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ BoolGrammarPtr routekey = new BoolGrammar; routekey->v = true; - (yyval) = GrammarBasePtr::dynamicCast(routekey); + yyval = GrammarBasePtr::dynamicCast(routekey); } -#line 2009 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1931 "tars.tab.cpp" break; - case 54: -#line 531 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 54: /* out_qualifier: TARS_OUT */ +#line 531 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ BoolGrammarPtr out = new BoolGrammar; out->v = true; - (yyval) = GrammarBasePtr::dynamicCast(out); + yyval = GrammarBasePtr::dynamicCast(out); } -#line 2019 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1941 "tars.tab.cpp" break; - case 55: -#line 542 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 55: /* @7: %empty */ +#line 542 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); NamespacePtr np = NamespacePtr::dynamicCast(g_parse->currentContainer()); if(np) { @@ -2029,11 +1951,11 @@ yyparse (void) if(sp) { g_parse->pushContainer(sp); - (yyval) = GrammarBasePtr::dynamicCast(sp); + yyval = GrammarBasePtr::dynamicCast(sp); } else { - (yyval) = 0; + yyval = 0; } } else @@ -2041,280 +1963,280 @@ yyparse (void) g_parse->error("struct '" + ident->v + "' must definition in namespace"); } } -#line 2045 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1967 "tars.tab.cpp" break; - case 56: -#line 564 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - if((yyvsp[-3])) + case 56: /* struct_def: struct_id @7 '{' struct_exports '}' */ +#line 564 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + if(yyvsp[-3]) { g_parse->popContainer(); } - (yyval) = (yyvsp[-3]); + yyval = yyvsp[-3]; - StructPtr st = StructPtr::dynamicCast((yyval)); + StructPtr st = StructPtr::dynamicCast(yyval); assert(st); if(st->getAllMemberPtr().size() == 0) { g_parse->error("struct `" + st->getSid() + "' must have at least one member"); } } -#line 2064 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1986 "tars.tab.cpp" break; - case 57: -#line 584 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = (yyvsp[0]); + case 57: /* struct_id: TARS_STRUCT TARS_IDENTIFIER */ +#line 584 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = yyvsp[0]; } -#line 2072 "tars.tab.cpp" /* yacc.c:1646 */ +#line 1994 "tars.tab.cpp" break; - case 58: -#line 588 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 58: /* struct_id: TARS_STRUCT keyword */ +#line 588 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); g_parse->error("keyword `" + ident->v + "' cannot be used as struct name"); } -#line 2082 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2004 "tars.tab.cpp" break; - case 59: -#line 594 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 59: /* struct_id: TARS_STRUCT error */ +#line 594 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("abstract declarator '' used as declaration"); } -#line 2090 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2012 "tars.tab.cpp" break; - case 60: -#line 603 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 60: /* struct_exports: data_member ';' struct_exports */ +#line 603 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2098 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2020 "tars.tab.cpp" break; - case 61: -#line 607 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 61: /* struct_exports: data_member */ +#line 607 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("';' missing after definition"); } -#line 2106 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2028 "tars.tab.cpp" break; - case 62: -#line 611 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 62: /* struct_exports: %empty */ +#line 611 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2113 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2035 "tars.tab.cpp" break; - case 63: -#line 621 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); + case 63: /* data_member: struct_type_id */ +#line 621 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); } -#line 2121 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2043 "tars.tab.cpp" break; - case 64: -#line 630 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 64: /* struct_type_id: TARS_CONST_INTEGER TARS_REQUIRE type_id */ +#line 630 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ StructPtr np = StructPtr::dynamicCast(g_parse->currentContainer()); if(np) { - IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast((yyvsp[-2])); + IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast(yyvsp[-2]); g_parse->checkTag(iPtr->v); - TypeIdPtr tPtr = TypeIdPtr::dynamicCast((yyvsp[0])); + TypeIdPtr tPtr = TypeIdPtr::dynamicCast(yyvsp[0]); tPtr->setRequire(iPtr->v); np->addTypeId(tPtr); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); } else { - (yyval) = 0; + yyval = 0; } } -#line 2143 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2065 "tars.tab.cpp" break; - case 65: -#line 648 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 65: /* struct_type_id: TARS_CONST_INTEGER TARS_REQUIRE type_id '=' const_initializer */ +#line 648 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ StructPtr np = StructPtr::dynamicCast(g_parse->currentContainer()); if(np) { - IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast((yyvsp[-4])); + IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast(yyvsp[-4]); g_parse->checkTag(iPtr->v); - TypeIdPtr tPtr = TypeIdPtr::dynamicCast((yyvsp[-2])); - ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast((yyvsp[0])); + TypeIdPtr tPtr = TypeIdPtr::dynamicCast(yyvsp[-2]); + ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast(yyvsp[0]); g_parse->checkConstValue(tPtr, sPtr->t); tPtr->setRequire(iPtr->v); tPtr->setDefault(sPtr->v); np->addTypeId(tPtr); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-2])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[-2]); } else { - (yyval) = 0; + yyval = 0; } } -#line 2169 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2091 "tars.tab.cpp" break; - case 66: -#line 670 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 66: /* struct_type_id: TARS_CONST_INTEGER TARS_OPTIONAL type_id '=' const_initializer */ +#line 670 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ StructPtr np = StructPtr::dynamicCast(g_parse->currentContainer()); if(np) { - IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast((yyvsp[-4])); + IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast(yyvsp[-4]); g_parse->checkTag(iPtr->v); - TypeIdPtr tPtr = TypeIdPtr::dynamicCast((yyvsp[-2])); - ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast((yyvsp[0])); + TypeIdPtr tPtr = TypeIdPtr::dynamicCast(yyvsp[-2]); + ConstGrammarPtr sPtr = ConstGrammarPtr::dynamicCast(yyvsp[0]); g_parse->checkConstValue(tPtr, sPtr->t); tPtr->setOptional(iPtr->v); tPtr->setDefault(sPtr->v); np->addTypeId(tPtr); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-2])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[-2]); } else { - (yyval) = 0; + yyval = 0; } } -#line 2195 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2117 "tars.tab.cpp" break; - case 67: -#line 692 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 67: /* struct_type_id: TARS_CONST_INTEGER TARS_OPTIONAL type_id */ +#line 692 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ StructPtr np = StructPtr::dynamicCast(g_parse->currentContainer()); if(np) { - IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast((yyvsp[-2])); + IntergerGrammarPtr iPtr = IntergerGrammarPtr::dynamicCast(yyvsp[-2]); g_parse->checkTag(iPtr->v); - TypeIdPtr tPtr = TypeIdPtr::dynamicCast((yyvsp[0])); + TypeIdPtr tPtr = TypeIdPtr::dynamicCast(yyvsp[0]); tPtr->setOptional(iPtr->v); np->addTypeId(tPtr); - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); + yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); } else { - (yyval) = 0; + yyval = 0; } } -#line 2216 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2138 "tars.tab.cpp" break; - case 68: -#line 709 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 68: /* struct_type_id: TARS_REQUIRE type_id */ +#line 709 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("struct member need 'tag'"); } -#line 2224 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2146 "tars.tab.cpp" break; - case 69: -#line 713 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 69: /* struct_type_id: TARS_OPTIONAL type_id */ +#line 713 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("struct member need 'tag'"); } -#line 2232 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2154 "tars.tab.cpp" break; - case 70: -#line 717 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 70: /* struct_type_id: TARS_CONST_INTEGER type_id */ +#line 717 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("struct member need 'require' or 'optional'"); } -#line 2240 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2162 "tars.tab.cpp" break; - case 71: -#line 721 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 71: /* struct_type_id: type_id */ +#line 721 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("struct member need 'tag' or 'require' or 'optional'"); } -#line 2248 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2170 "tars.tab.cpp" break; - case 72: -#line 730 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - IntergerGrammarPtr intVal = IntergerGrammarPtr::dynamicCast((yyvsp[0])); + case 72: /* const_initializer: TARS_CONST_INTEGER */ +#line 730 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + IntergerGrammarPtr intVal = IntergerGrammarPtr::dynamicCast(yyvsp[0]); ostringstream sstr; sstr << intVal->v; ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::VALUE; c->v = sstr.str(); - (yyval) = c; + yyval = c; } -#line 2262 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2184 "tars.tab.cpp" break; - case 73: -#line 740 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - FloatGrammarPtr floatVal = FloatGrammarPtr::dynamicCast((yyvsp[0])); + case 73: /* const_initializer: TARS_CONST_FLOAT */ +#line 740 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + FloatGrammarPtr floatVal = FloatGrammarPtr::dynamicCast(yyvsp[0]); ostringstream sstr; sstr << floatVal->v; ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::VALUE; c->v = sstr.str(); - (yyval) = c; + yyval = c; } -#line 2276 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2198 "tars.tab.cpp" break; - case 74: -#line 750 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 74: /* const_initializer: TARS_STRING_LITERAL */ +#line 750 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::STRING; c->v = ident->v; - (yyval) = c; + yyval = c; } -#line 2288 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2210 "tars.tab.cpp" break; - case 75: -#line 758 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 75: /* const_initializer: TARS_FALSE */ +#line 758 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::BOOL; c->v = ident->v; - (yyval) = c; + yyval = c; } -#line 2300 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2222 "tars.tab.cpp" break; - case 76: -#line 766 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 76: /* const_initializer: TARS_TRUE */ +#line 766 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::BOOL; c->v = ident->v; - (yyval) = c; + yyval = c; } -#line 2312 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2234 "tars.tab.cpp" break; - case 77: -#line 774 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 77: /* const_initializer: TARS_IDENTIFIER */ +#line 774 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); if (g_parse->checkEnum(ident->v) == false) { @@ -2323,17 +2245,17 @@ yyparse (void) ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::ENUM; c->v = ident->v; - (yyval) = c; + yyval = c; } -#line 2329 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2251 "tars.tab.cpp" break; - case 78: -#line 787 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 78: /* const_initializer: scoped_name TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ +#line 787 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ - StringGrammarPtr scoped = StringGrammarPtr::dynamicCast((yyvsp[-2])); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + StringGrammarPtr scoped = StringGrammarPtr::dynamicCast(yyvsp[-2]); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); if (g_parse->checkEnum(ident->v) == false) { @@ -2342,511 +2264,512 @@ yyparse (void) ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::ENUM; c->v = scoped->v + "::" + ident->v; - (yyval) = c; + yyval = c; } -#line 2348 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2270 "tars.tab.cpp" break; - case 79: -#line 807 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 79: /* const_def: TARS_CONST type_id '=' const_initializer */ +#line 807 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ NamespacePtr np = NamespacePtr::dynamicCast(g_parse->currentContainer()); if(!np) { g_parse->error("const type must define in namespace"); } - TypeIdPtr t = TypeIdPtr::dynamicCast((yyvsp[-2])); - ConstGrammarPtr c = ConstGrammarPtr::dynamicCast((yyvsp[0])); + TypeIdPtr t = TypeIdPtr::dynamicCast(yyvsp[-2]); + ConstGrammarPtr c = ConstGrammarPtr::dynamicCast(yyvsp[0]); ConstPtr cPtr = np->createConst(t, c); - (yyval) = cPtr; + yyval = cPtr; } -#line 2365 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2287 "tars.tab.cpp" break; - case 80: -#line 825 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypePtr type = TypePtr::dynamicCast((yyvsp[-1])); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 80: /* type_id: type TARS_IDENTIFIER */ +#line 825 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypePtr type = TypePtr::dynamicCast(yyvsp[-1]); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); TypeIdPtr typeIdPtr = new TypeId(type, ident->v); - (yyval) = GrammarBasePtr::dynamicCast(typeIdPtr); + yyval = GrammarBasePtr::dynamicCast(typeIdPtr); } -#line 2378 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2300 "tars.tab.cpp" break; - case 81: -#line 834 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypePtr type = g_parse->createVector(TypePtr::dynamicCast((yyvsp[-4]))); - IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast((yyvsp[-1])); + case 81: /* type_id: type TARS_IDENTIFIER '[' TARS_CONST_INTEGER ']' */ +#line 834 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypePtr type = g_parse->createVector(TypePtr::dynamicCast(yyvsp[-4])); + IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast(yyvsp[-1]); g_parse->checkArrayVaid(type,iPtrSize->v); type->setArray(iPtrSize->v); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[-3])); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-3]); TypeIdPtr typeIdPtr = new TypeId(type, ident->v); - (yyval) = GrammarBasePtr::dynamicCast(typeIdPtr); + yyval = GrammarBasePtr::dynamicCast(typeIdPtr); } -#line 2392 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2314 "tars.tab.cpp" break; - case 82: -#line 844 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypePtr type = g_parse->createVector(TypePtr::dynamicCast((yyvsp[-2]))); + case 82: /* type_id: type '*' TARS_IDENTIFIER */ +#line 844 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypePtr type = g_parse->createVector(TypePtr::dynamicCast(yyvsp[-2])); //IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast($4); g_parse->checkPointerVaid(type); type->setPointer(true); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); TypeIdPtr typeIdPtr = new TypeId(type, ident->v); - (yyval) = GrammarBasePtr::dynamicCast(typeIdPtr); + yyval = GrammarBasePtr::dynamicCast(typeIdPtr); } -#line 2406 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2328 "tars.tab.cpp" break; - case 83: -#line 854 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - TypePtr type = TypePtr::dynamicCast((yyvsp[-3])); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[-2])); + case 83: /* type_id: type TARS_IDENTIFIER ':' TARS_CONST_INTEGER */ +#line 854 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + TypePtr type = TypePtr::dynamicCast(yyvsp[-3]); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-2]); TypeIdPtr typeIdPtr = new TypeId(type, ident->v); - IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast((yyvsp[-1])); + IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast(yyvsp[-1]); g_parse->checkArrayVaid(type,iPtrSize->v); - (yyval) = GrammarBasePtr::dynamicCast(typeIdPtr); + yyval = GrammarBasePtr::dynamicCast(typeIdPtr); } -#line 2419 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2341 "tars.tab.cpp" break; - case 84: -#line 863 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 84: /* type_id: type keyword */ +#line 863 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); g_parse->error("keyword `" + ident->v + "' cannot be used as data member name"); } -#line 2428 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2350 "tars.tab.cpp" break; - case 85: -#line 868 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 85: /* type_id: type */ +#line 868 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("missing data member name"); } -#line 2436 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2358 "tars.tab.cpp" break; - case 86: -#line 872 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 86: /* type_id: error */ +#line 872 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("unkown type"); } -#line 2444 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2366 "tars.tab.cpp" break; - case 87: -#line 881 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 87: /* type: type_no ':' TARS_CONST_INTEGER */ +#line 881 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ - TypePtr type = TypePtr::dynamicCast((yyvsp[-2])); - IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast((yyvsp[0])); + TypePtr type = TypePtr::dynamicCast(yyvsp[-2]); + IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast(yyvsp[0]); g_parse->checkArrayVaid(type,iPtrSize->v); type->setArray(iPtrSize->v); - (yyval) = type; + yyval = type; } -#line 2457 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2379 "tars.tab.cpp" break; - case 88: -#line 890 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = (yyvsp[0]); + case 88: /* type: type_no */ +#line 890 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = yyvsp[0]; } -#line 2465 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2387 "tars.tab.cpp" break; - case 89: -#line 894 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 89: /* type: type_no ':' error */ +#line 894 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("array missing size"); } -#line 2473 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2395 "tars.tab.cpp" break; - case 90: -#line 903 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindBool); + case 90: /* type_no: TARS_BOOL */ +#line 903 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindBool); } -#line 2481 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2403 "tars.tab.cpp" break; - case 91: -#line 907 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindByte); + case 91: /* type_no: TARS_BYTE */ +#line 907 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindByte); } -#line 2489 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2411 "tars.tab.cpp" break; - case 92: -#line 911 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindShort,true); + case 92: /* type_no: TARS_UNSIGNED TARS_BYTE */ +#line 911 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindShort,true); } -#line 2497 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2419 "tars.tab.cpp" break; - case 93: -#line 915 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindShort); + case 93: /* type_no: TARS_SHORT */ +#line 915 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindShort); } -#line 2505 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2427 "tars.tab.cpp" break; - case 94: -#line 919 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindInt,true); + case 94: /* type_no: TARS_UNSIGNED TARS_SHORT */ +#line 919 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindInt,true); } -#line 2513 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2435 "tars.tab.cpp" break; - case 95: -#line 923 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindInt); + case 95: /* type_no: TARS_INT */ +#line 923 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindInt); } -#line 2521 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2443 "tars.tab.cpp" break; - case 96: -#line 927 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindLong,true); + case 96: /* type_no: TARS_UNSIGNED TARS_INT */ +#line 927 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindLong,true); } -#line 2529 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2451 "tars.tab.cpp" break; - case 97: -#line 931 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindLong); + case 97: /* type_no: TARS_LONG */ +#line 931 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindLong); } -#line 2537 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2459 "tars.tab.cpp" break; - case 98: -#line 935 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindFloat); + case 98: /* type_no: TARS_FLOAT */ +#line 935 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindFloat); } -#line 2545 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2467 "tars.tab.cpp" break; - case 99: -#line 939 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindDouble); + case 99: /* type_no: TARS_DOUBLE */ +#line 939 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindDouble); } -#line 2553 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2475 "tars.tab.cpp" break; - case 100: -#line 943 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = g_parse->createBuiltin(Builtin::KindString); + case 100: /* type_no: TARS_STRING */ +#line 943 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = g_parse->createBuiltin(Builtin::KindString); } -#line 2561 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2483 "tars.tab.cpp" break; - case 101: -#line 947 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); + case 101: /* type_no: vector */ +#line 947 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); } -#line 2569 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2491 "tars.tab.cpp" break; - case 102: -#line 951 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); + case 102: /* type_no: map */ +#line 951 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); } -#line 2577 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2499 "tars.tab.cpp" break; - case 103: -#line 955 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 103: /* type_no: scoped_name */ +#line 955 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); TypePtr sp = g_parse->findUserType(ident->v); if(sp) { - (yyval) = GrammarBasePtr::dynamicCast(sp); + yyval = GrammarBasePtr::dynamicCast(sp); } else { g_parse->error("'" + ident->v + "' undefined!"); } } -#line 2594 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2516 "tars.tab.cpp" break; - case 104: -#line 973 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = GrammarBasePtr::dynamicCast(g_parse->createVector(TypePtr::dynamicCast((yyvsp[-1])))); + case 104: /* vector: TARS_VECTOR '<' type '>' */ +#line 973 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = GrammarBasePtr::dynamicCast(g_parse->createVector(TypePtr::dynamicCast(yyvsp[-1]))); } -#line 2602 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2524 "tars.tab.cpp" break; - case 105: -#line 977 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 105: /* vector: TARS_VECTOR '<' error */ +#line 977 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("vector error"); } -#line 2610 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2532 "tars.tab.cpp" break; - case 106: -#line 981 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 106: /* vector: TARS_VECTOR '<' type error */ +#line 981 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("vector missing '>'"); } -#line 2618 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2540 "tars.tab.cpp" break; - case 107: -#line 985 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 107: /* vector: TARS_VECTOR error */ +#line 985 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("vector missing type"); } -#line 2626 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2548 "tars.tab.cpp" break; - case 108: -#line 994 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - (yyval) = GrammarBasePtr::dynamicCast(g_parse->createMap(TypePtr::dynamicCast((yyvsp[-3])), TypePtr::dynamicCast((yyvsp[-1])))); + case 108: /* map: TARS_MAP '<' type ',' type '>' */ +#line 994 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + yyval = GrammarBasePtr::dynamicCast(g_parse->createMap(TypePtr::dynamicCast(yyvsp[-3]), TypePtr::dynamicCast(yyvsp[-1]))); } -#line 2634 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2556 "tars.tab.cpp" break; - case 109: -#line 998 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 109: /* map: TARS_MAP '<' error */ +#line 998 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ g_parse->error("map error"); } -#line 2642 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2564 "tars.tab.cpp" break; - case 110: -#line 1007 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 110: /* scoped_name: TARS_IDENTIFIER */ +#line 1007 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2649 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2571 "tars.tab.cpp" break; - case 111: -#line 1010 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 111: /* scoped_name: TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ +#line 1010 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); ident->v = "::" + ident->v; - (yyval) = GrammarBasePtr::dynamicCast(ident); + yyval = GrammarBasePtr::dynamicCast(ident); } -#line 2659 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2581 "tars.tab.cpp" break; - case 112: -#line 1016 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { - StringGrammarPtr scoped = StringGrammarPtr::dynamicCast((yyvsp[-2])); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); + case 112: /* scoped_name: scoped_name TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ +#line 1016 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ + StringGrammarPtr scoped = StringGrammarPtr::dynamicCast(yyvsp[-2]); + StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); scoped->v += "::"; scoped->v += ident->v; - (yyval) = GrammarBasePtr::dynamicCast(scoped); + yyval = GrammarBasePtr::dynamicCast(scoped); } -#line 2671 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2593 "tars.tab.cpp" break; - case 113: -#line 1029 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 113: /* keyword: TARS_STRUCT */ +#line 1029 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2678 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2600 "tars.tab.cpp" break; - case 114: -#line 1032 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 114: /* keyword: TARS_VOID */ +#line 1032 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2685 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2607 "tars.tab.cpp" break; - case 115: -#line 1035 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 115: /* keyword: TARS_BOOL */ +#line 1035 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2692 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2614 "tars.tab.cpp" break; - case 116: -#line 1038 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 116: /* keyword: TARS_BYTE */ +#line 1038 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2699 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2621 "tars.tab.cpp" break; - case 117: -#line 1041 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 117: /* keyword: TARS_SHORT */ +#line 1041 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2706 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2628 "tars.tab.cpp" break; - case 118: -#line 1044 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 118: /* keyword: TARS_INT */ +#line 1044 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2713 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2635 "tars.tab.cpp" break; - case 119: -#line 1047 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 119: /* keyword: TARS_FLOAT */ +#line 1047 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2720 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2642 "tars.tab.cpp" break; - case 120: -#line 1050 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 120: /* keyword: TARS_DOUBLE */ +#line 1050 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2727 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2649 "tars.tab.cpp" break; - case 121: -#line 1053 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 121: /* keyword: TARS_STRING */ +#line 1053 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2734 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2656 "tars.tab.cpp" break; - case 122: -#line 1056 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 122: /* keyword: TARS_VECTOR */ +#line 1056 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2741 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2663 "tars.tab.cpp" break; - case 123: -#line 1059 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 123: /* keyword: TARS_KEY */ +#line 1059 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2748 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2670 "tars.tab.cpp" break; - case 124: -#line 1062 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 124: /* keyword: TARS_MAP */ +#line 1062 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2755 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2677 "tars.tab.cpp" break; - case 125: -#line 1065 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 125: /* keyword: TARS_NAMESPACE */ +#line 1065 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2762 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2684 "tars.tab.cpp" break; - case 126: -#line 1068 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 126: /* keyword: TARS_INTERFACE */ +#line 1068 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2769 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2691 "tars.tab.cpp" break; - case 127: -#line 1071 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 127: /* keyword: TARS_OUT */ +#line 1071 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2776 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2698 "tars.tab.cpp" break; - case 128: -#line 1074 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 128: /* keyword: TARS_REQUIRE */ +#line 1074 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2783 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2705 "tars.tab.cpp" break; - case 129: -#line 1077 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 129: /* keyword: TARS_OPTIONAL */ +#line 1077 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2790 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2712 "tars.tab.cpp" break; - case 130: -#line 1080 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 130: /* keyword: TARS_CONST_INTEGER */ +#line 1080 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2797 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2719 "tars.tab.cpp" break; - case 131: -#line 1083 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 131: /* keyword: TARS_CONST_FLOAT */ +#line 1083 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2804 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2726 "tars.tab.cpp" break; - case 132: -#line 1086 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 132: /* keyword: TARS_FALSE */ +#line 1086 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2811 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2733 "tars.tab.cpp" break; - case 133: -#line 1089 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 133: /* keyword: TARS_TRUE */ +#line 1089 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2818 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2740 "tars.tab.cpp" break; - case 134: -#line 1092 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 134: /* keyword: TARS_STRING_LITERAL */ +#line 1092 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2825 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2747 "tars.tab.cpp" break; - case 135: -#line 1095 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 135: /* keyword: TARS_CONST */ +#line 1095 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2832 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2754 "tars.tab.cpp" break; - case 136: -#line 1098 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 136: /* keyword: TARS_ENUM */ +#line 1098 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2839 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2761 "tars.tab.cpp" break; - case 137: -#line 1101 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ - { + case 137: /* keyword: TARS_UNSIGNED */ +#line 1101 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" +{ } -#line 2846 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2768 "tars.tab.cpp" break; -#line 2850 "tars.tab.cpp" /* yacc.c:1646 */ +#line 2772 "tars.tab.cpp" + default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2860,25 +2783,23 @@ yyparse (void) case of YYERROR or YYBACKUP, subsequent parser actions might lead to an incorrect destructor call or verbose syntax error message before the lookahead is translated. */ - YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + YY_SYMBOL_PRINT ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; - YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; /* Now 'shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ - - yyn = yyr1[yyn]; - - yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; + { + const int yylhs = yyr1[yyn] - YYNTOKENS; + const int yyi = yypgoto[yylhs] + *yyssp; + yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp + ? yytable[yyi] + : yydefgoto[yylhs]); + } goto yynewstate; @@ -2889,50 +2810,14 @@ yyparse (void) yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); - + yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; -#if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); -#else -# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) - { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; - } -# undef YYSYNTAX_ERROR -#endif } - - if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an @@ -2961,12 +2846,10 @@ yyparse (void) | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: - - /* Pacify compilers like GCC when the user code never invokes - YYERROR and the label yyerrorlab therefore never appears in user - code. */ - if (/*CONSTCOND*/ 0) - goto yyerrorlab; + /* Pacify compilers when the user code never invokes YYERROR and the + label yyerrorlab therefore never appears in user code. */ + if (0) + YYERROR; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ @@ -2983,13 +2866,14 @@ yyparse (void) yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ + /* Pop stack until we find a state that shifts the error token. */ for (;;) { yyn = yypact[yystate]; if (!yypact_value_is_default (yyn)) { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + yyn += YYSYMBOL_YYerror; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) { yyn = yytable[yyn]; if (0 < yyn) @@ -3003,7 +2887,7 @@ yyparse (void) yydestruct ("Error: popping", - yystos[yystate], yyvsp); + YY_ACCESSING_SYMBOL (yystate), yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -3015,7 +2899,7 @@ yyparse (void) /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -3028,6 +2912,7 @@ yyparse (void) yyresult = 0; goto yyreturn; + /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ @@ -3035,16 +2920,21 @@ yyparse (void) yyresult = 1; goto yyreturn; -#if !defined yyoverflow || YYERROR_VERBOSE + +#if !defined yyoverflow /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; - /* Fall through. */ + goto yyreturn; #endif + +/*-------------------------------------------------------. +| yyreturn -- parsing is finished, clean up and return. | +`-------------------------------------------------------*/ yyreturn: if (yychar != YYEMPTY) { @@ -3061,20 +2951,18 @@ yyparse (void) while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp); + YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif -#if YYERROR_VERBOSE - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); -#endif + return yyresult; } -#line 1105 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1906 */ + +#line 1105 "/Volumes/MyData/centos/boat/boat-code/tarscpp/tools/tarsgrammar/tars.y" diff --git a/tools/tarsparse/tars.tab.hpp b/tools/tarsparse/tars.tab.hpp index 547e0174..7a3f80ae 100644 --- a/tools/tarsparse/tars.tab.hpp +++ b/tools/tarsparse/tars.tab.hpp @@ -1,8 +1,9 @@ -/* A Bison parser, made by GNU Bison 3.0.4. */ +/* A Bison parser, made by GNU Bison 3.7.6. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc. + Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, + Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -15,7 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program. If not, see . */ + along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work @@ -30,6 +31,10 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ +/* DO NOT RELY ON FEATURES THAT ARE NOT DOCUMENTED in the manual, + especially those whose name start with YY_ or yy_. They are + private implementation details that can be changed or removed. */ + #ifndef YY_YY_TARS_TAB_HPP_INCLUDED # define YY_YY_TARS_TAB_HPP_INCLUDED /* Debug traces. */ @@ -40,43 +45,48 @@ extern int yydebug; #endif -/* Token type. */ +/* Token kinds. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE enum yytokentype { - TARS_VOID = 258, - TARS_STRUCT = 259, - TARS_BOOL = 260, - TARS_BYTE = 261, - TARS_SHORT = 262, - TARS_INT = 263, - TARS_DOUBLE = 264, - TARS_FLOAT = 265, - TARS_LONG = 266, - TARS_STRING = 267, - TARS_VECTOR = 268, - TARS_MAP = 269, - TARS_NAMESPACE = 270, - TARS_INTERFACE = 271, - TARS_IDENTIFIER = 272, - TARS_OUT = 273, - TARS_OP = 274, - TARS_KEY = 275, - TARS_ROUTE_KEY = 276, - TARS_REQUIRE = 277, - TARS_OPTIONAL = 278, - TARS_CONST_INTEGER = 279, - TARS_CONST_FLOAT = 280, - TARS_FALSE = 281, - TARS_TRUE = 282, - TARS_STRING_LITERAL = 283, - TARS_SCOPE_DELIMITER = 284, - TARS_CONST = 285, - TARS_ENUM = 286, - TARS_UNSIGNED = 287, - BAD_CHAR = 288 + YYEMPTY = -2, + YYEOF = 0, /* "end of file" */ + YYerror = 256, /* error */ + YYUNDEF = 257, /* "invalid token" */ + TARS_VOID = 258, /* TARS_VOID */ + TARS_STRUCT = 259, /* TARS_STRUCT */ + TARS_BOOL = 260, /* TARS_BOOL */ + TARS_BYTE = 261, /* TARS_BYTE */ + TARS_SHORT = 262, /* TARS_SHORT */ + TARS_INT = 263, /* TARS_INT */ + TARS_DOUBLE = 264, /* TARS_DOUBLE */ + TARS_FLOAT = 265, /* TARS_FLOAT */ + TARS_LONG = 266, /* TARS_LONG */ + TARS_STRING = 267, /* TARS_STRING */ + TARS_VECTOR = 268, /* TARS_VECTOR */ + TARS_MAP = 269, /* TARS_MAP */ + TARS_NAMESPACE = 270, /* TARS_NAMESPACE */ + TARS_INTERFACE = 271, /* TARS_INTERFACE */ + TARS_IDENTIFIER = 272, /* TARS_IDENTIFIER */ + TARS_OUT = 273, /* TARS_OUT */ + TARS_OP = 274, /* TARS_OP */ + TARS_KEY = 275, /* TARS_KEY */ + TARS_ROUTE_KEY = 276, /* TARS_ROUTE_KEY */ + TARS_REQUIRE = 277, /* TARS_REQUIRE */ + TARS_OPTIONAL = 278, /* TARS_OPTIONAL */ + TARS_CONST_INTEGER = 279, /* TARS_CONST_INTEGER */ + TARS_CONST_FLOAT = 280, /* TARS_CONST_FLOAT */ + TARS_FALSE = 281, /* TARS_FALSE */ + TARS_TRUE = 282, /* TARS_TRUE */ + TARS_STRING_LITERAL = 283, /* TARS_STRING_LITERAL */ + TARS_SCOPE_DELIMITER = 284, /* TARS_SCOPE_DELIMITER */ + TARS_CONST = 285, /* TARS_CONST */ + TARS_ENUM = 286, /* TARS_ENUM */ + TARS_UNSIGNED = 287, /* TARS_UNSIGNED */ + BAD_CHAR = 288 /* BAD_CHAR */ }; + typedef enum yytokentype yytoken_kind_t; #endif /* Value type. */ diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index fcaac208..6c9154ae 100755 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -1,5 +1,6 @@ project(unit-test) + include_directories(${servant_SOURCE_DIR}/protocol/framework) include_directories(${servant_SOURCE_DIR}/protocol/servant) @@ -7,10 +8,15 @@ include_directories(${CMAKE_BINARY_DIR}/src/gtest/include) link_directories(${CMAKE_BINARY_DIR}/src/gtest/lib) link_directories(${CMAKE_BINARY_DIR}/src/gtest/lib64) include_directories(./) +include_directories(../) build_tars_server("unit-test" "") add_definitions(-DCMAKE_SOURCE_DIR="${PROJECT_SOURCE_DIR}") -target_link_libraries(unit-test ${LIB_GTEST}) +target_link_libraries(unit-test ${LIB_GTEST} tarsmock) + +if(TARS_MYSQL) + target_link_libraries(unit-test ${LIB_MYSQL}) +endif() -add_dependencies(unit-test FRAMEWORK-PROTOCOL) +add_dependencies(unit-test FRAMEWORK-PROTOCOL tarsmock) diff --git a/unit-test/certs.h b/unit-test/certs.h index 4513bc15..d7f5dc56 100755 --- a/unit-test/certs.h +++ b/unit-test/certs.h @@ -2,6 +2,7 @@ #define PATH_HEAER #include "util/tc_config.h" +#include "mock/framework.h" using namespace tars; @@ -30,7 +31,7 @@ inline TC_Config CLIENT_CONFIG() inline TC_Config FRAMEWORK_CONFIG() { TC_Config conf; - conf.parseFile(CONFIGPATH + "/server/framework.conf"); + conf.parseString(MOCK_FRAMEWORK_CONFIG); return conf; } diff --git a/unit-test/hello_test.cpp b/unit-test/hello_test.cpp index 32d684f1..1f458957 100755 --- a/unit-test/hello_test.cpp +++ b/unit-test/hello_test.cpp @@ -278,7 +278,7 @@ void HelloTest::asyncCustom(Communicator *comm, const string &adapter) //发起远程调用 for (int j = 0; j < _count; ++j) { - CustomCallBackPtr cb = new CustomCallBack(callback_count); + ServantProxyCallbackPtr cb(new CustomCallBack(callback_count)); prx->rpc_call_async(prx->tars_gen_requestid(), "doCustomFunc", _buffer.c_str(), _buffer.length(), cb); } @@ -297,7 +297,8 @@ void HelloTest::testPush(Communicator *comm, const string &adapter) prx->tars_set_protocol(prot); - PushCallBackPtr cbPush = new PushCallBack(); + PushCallBack *c = new PushCallBack(); + ServantProxyCallbackPtr cbPush(c); prx->tars_set_push_callback(cbPush); string buf("heartbeat"); @@ -305,20 +306,22 @@ void HelloTest::testPush(Communicator *comm, const string &adapter) int count = 2; while(count-- > 0) { - cbPush->_onconnect = false; - cbPush->_onclose = false; + c->_onconnect = false; + c->_onclose = false; - PushCallBackPtr cb = new PushCallBack(); + PushCallBack *cNew = new PushCallBack(); + + ServantProxyCallbackPtr cb(cNew); prx->rpc_call_async(prx->tars_gen_requestid(), "printResult", buf.c_str(), buf.length(), cb); wait(1000); - ASSERT_TRUE(cbPush->_onconnect); - ASSERT_TRUE(cb->_onprintresult); + ASSERT_TRUE(c->_onconnect); + ASSERT_TRUE(cNew->_onprintresult); wait(10000); - ASSERT_TRUE(cbPush->_onclose); + ASSERT_TRUE(c->_onclose); } } @@ -333,24 +336,25 @@ void HelloTest::testReconnect(Communicator *comm, const string &adapter ) prx->tars_set_protocol(prot); prx->tars_reconnect(1); - PushCallBackPtr cbPush = new PushCallBack(); + PushCallBack *c = new PushCallBack(); + ServantProxyCallbackPtr cbPush(c); prx->tars_set_push_callback(cbPush); string buf("heartbeat"); - cbPush->_onconnect = false; - cbPush->_onclose = false; + c->_onconnect = false; + c->_onclose = false; ResponsePacket rsp; prx->rpc_call(prx->tars_gen_requestid(), "printResult", buf.c_str(), buf.length(), rsp); TC_Common::msleep(10500); - ASSERT_TRUE(cbPush->_onclose); + ASSERT_TRUE(c->_onclose); TC_Common::msleep(2000); - ASSERT_TRUE(cbPush->_onconnect); + ASSERT_TRUE(c->_onconnect); } @@ -493,7 +497,7 @@ void HelloTest::checkASyncOnce(HelloPrx prx) atomic callback_count{0}; - HelloPrxCallbackPtr p = new ClientHelloCallback(prx, callback_count); + HelloPrxCallbackPtr p(new ClientHelloCallback(prx, callback_count)); prx->async_testHello(p, 0, _buffer); @@ -548,7 +552,7 @@ void HelloTest::checkASync(Communicator *comm, const string &adapter) //发起远程调用 for (int j = 0; j < _count; ++j) { - HelloPrxCallbackPtr p = new ClientHelloCallback(TC_Common::now2us(), j, _count, _buffer, callback_count); + HelloPrxCallbackPtr p(new ClientHelloCallback(TC_Common::now2us(), j, _count, _buffer, callback_count)); prx->async_testHello(p, j, _buffer); } @@ -647,7 +651,7 @@ void HelloTest::checkTransASyncASync(Communicator *comm) //发起远程调用 for (int j = 0; j < _count; ++j) { - HelloPrxCallbackPtr p = new ClientHelloCallback(TC_Common::now2us(), j, _count, _buffer, callback_count); + HelloPrxCallbackPtr p(new ClientHelloCallback(TC_Common::now2us(), j, _count, _buffer, callback_count)); prx->async_testTrans(p, j, _buffer); } @@ -689,7 +693,7 @@ void HelloTest::checkTransASyncSync(Communicator *comm) //发起远程调用 for (int j = 0; j < _count; ++j) { - HelloPrxCallbackPtr p = new ClientHelloCallback(TC_Common::now2us(), j, _count, _buffer, callback_count); + HelloPrxCallbackPtr p(new ClientHelloCallback(TC_Common::now2us(), j, _count, _buffer, callback_count)); prx->async_testSyncTrans(p, j, _buffer); } @@ -806,7 +810,7 @@ void HelloTest::checkASyncTimeout(Communicator *comm) std::atomic callback_count; ClientHelloCallback *c = new ClientHelloCallback(TC_Common::now2us(), 0, _count, _buffer, callback_count); - HelloPrxCallbackPtr p = c; + HelloPrxCallbackPtr p(c); prx->async_testTimeout(p, 1); @@ -862,7 +866,7 @@ void HelloTest::forEach(function func) HelloServer server; startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) i); - func(server.getCommunicator().get()); + func(server.getApplicationCommunicator().get()); stopServer(server); } @@ -891,7 +895,7 @@ void HelloTest::forEachInCoroutine(function func) s->terminate(); }); - func(server.getCommunicator().get()); + func(server.getApplicationCommunicator().get()); }); diff --git a/unit-test/hello_test.h b/unit-test/hello_test.h index 8bc92905..571581f3 100755 --- a/unit-test/hello_test.h +++ b/unit-test/hello_test.h @@ -42,13 +42,13 @@ class PushCallBack : public ServantProxyCallback void onConnect(const TC_Endpoint &ep) { _onconnect = true; -// LOG_CONSOLE_DEBUG << "onConnect:" << ep.toString() << ", " << _onconnect << ", " << this << endl; + LOG_CONSOLE_DEBUG << "onConnect:" << ep.toString() << ", " << _onconnect << ", " << this << endl; } void onClose() { _onclose = true; -// LOG_CONSOLE_DEBUG << "onClose:" << _onclose << endl; + LOG_CONSOLE_DEBUG << "onClose:" << _onclose << endl; } bool _onclose = false; @@ -58,7 +58,7 @@ class PushCallBack : public ServantProxyCallback }; -typedef tars::TC_AutoPtr PushCallBackPtr; +// typedef tars::TC_AutoPtr PushCallBackPtr; struct ClientHelloCallback : public HelloPrxCallback { @@ -185,7 +185,7 @@ class CustomCallBack : public ServantProxyCallback std::atomic &callback_count; }; -typedef tars::TC_AutoPtr CustomCallBackPtr; +// typedef tars::TC_AutoPtr CustomCallBackPtr; class HelloTest : public testing::Test { @@ -193,8 +193,11 @@ class HelloTest : public testing::Test //添加日志 static void SetUpTestCase() { + LocalRollLogger::getInstance()->setLogInfo("tars", "test", ".", 1024*1024*10, 5, nullptr, ""); + + LocalRollLogger::getInstance()->logger()->setLogLevel("TARS"); + } - } static void TearDownTestCase() { } @@ -259,7 +262,7 @@ class HelloTest : public testing::Test // comm->setProperty("asyncqueuecap", "1000000"); string obj = getObj(_conf, adapter); - LOG_CONSOLE_DEBUG << obj << endl; +// LOG_CONSOLE_DEBUG << obj << endl; T prx = comm->stringToProxy(obj); prx->tars_timeout(60000); @@ -268,8 +271,11 @@ class HelloTest : public testing::Test return prx; } - int GetUsedFileDescriptorCount() - { + int getFdCounts() + { +#if TARGET_PLATFORM_WINDOWS + return 0; +#else // 使用 shell 命令 "lsof" 获取已使用的文件句柄数量 FILE* file = popen("lsof -p $$ | wc -l", "r"); if (!file) { @@ -287,14 +293,6 @@ class HelloTest : public testing::Test // 解析结果并提取文件句柄数量 int usedFileDescriptors = std::stoi(result); return usedFileDescriptors; - } - - int getFdCounts() - { -#if TARGET_PLATFORM_WINDOWS - return 0; -#else - return GetUsedFileDescriptorCount(); #endif } @@ -381,7 +379,6 @@ class HelloTest : public testing::Test protected: int _count = 1000; - // int _count = 10; string _buffer; diff --git a/unit-test/rpc/test_admin.cpp b/unit-test/rpc/test_admin.cpp index 84bd3c66..549cecf0 100755 --- a/unit-test/rpc/test_admin.cpp +++ b/unit-test/rpc/test_admin.cpp @@ -17,29 +17,32 @@ #include "hello_test.h" #include "../server/WinServer.h" #include "servant/AdminF.h" -#include "server/FrameworkServer.h" -#include "server/framework/DbHandle.h" +#include "mock/TarsMockUtil.h" +#include "mock/DbHandle.h" +#include "mock/ConfigImp.h" TEST_F(HelloTest, testAdmin) { - FrameworkServer fs; - startServer(fs, FRAMEWORK_CONFIG()); + TarsMockUtil tarsMockUtil; + tarsMockUtil.startFramework(); + ConfigImp::setConfigFile("test.conf", "test-content"); CDbHandle::cleanEndPoint(); - CDbHandle::addActiveEndPoint("TestApp.FrameworkServer.ConfigObj", 11003, 1); WinServer ws; startServer(ws, WIN_CONFIG()); -// auto c = getCommunicator(); - - CommunicatorPtr c = ws.getCommunicator(); + CommunicatorPtr c = ws.getApplicationCommunicator(); string adminObj = "AdminObj@" + getLocalEndpoint(WIN_CONFIG()).toString(); AdminFPrx adminFPrx = c->stringToProxy(adminObj); + adminFPrx->tars_ping(); + + LOG_CONSOLE_DEBUG << endl; string loadconfig = adminFPrx->notify("tars.loadconfig test.conf"); + LOG_CONSOLE_DEBUG << loadconfig << endl; EXPECT_TRUE(loadconfig.find("[succ] get remote config:") != string::npos); loadconfig = adminFPrx->notify("tars.loadconfig no-test.conf"); @@ -75,11 +78,6 @@ TEST_F(HelloTest, testAdmin) string reloadlocator = adminFPrx->notify("tars.reloadlocator reload"); EXPECT_TRUE(reloadlocator.find("[notify prefix object num:1]") != string::npos); -// string closecore = adminFPrx->notify("tars.closecore no"); -// EXPECT_TRUE(closecore.find("after set cur:18446744073709551615;max: 18446744073709551615") != string::npos); -// closecore = adminFPrx->notify("tars.closecore yes"); -// EXPECT_TRUE(closecore.find("after set cur:0;max: 18446744073709551615") != string::npos); - string errorcmd = adminFPrx->notify("tars.errorcmd"); EXPECT_STREQ(errorcmd.c_str(), ""); @@ -90,8 +88,6 @@ TEST_F(HelloTest, testAdmin) EXPECT_STREQ(normaldeletecmd.c_str(), "[notify servant object num:1]\n[1]:Delete success!\n"); stopServer(ws); - stopServer(fs); + tarsMockUtil.stopFramework(); } - - diff --git a/unit-test/rpc/test_async_rpc.cpp b/unit-test/rpc/test_async_rpc.cpp index 0ddf7662..7d2100b3 100755 --- a/unit-test/rpc/test_async_rpc.cpp +++ b/unit-test/rpc/test_async_rpc.cpp @@ -12,6 +12,7 @@ TEST_F(HelloTest, test) } + TEST_F(HelloTest, rpcASyncGlobalCommunicator) { { @@ -126,7 +127,7 @@ TEST_F(HelloTest, rpcASyncThreadFinish) //发起远程调用 for (int j = 0; j < count; ++j) { - HelloPrxCallbackPtr p = new ClientHelloCallback(TC_Common::now2us(), j, count, _buffer, callback_count); + HelloPrxCallbackPtr p(new ClientHelloCallback(TC_Common::now2us(), j, count, _buffer, callback_count)); prx->async_testHello(p, j, _buffer); } diff --git a/unit-test/rpc/test_communicator.cpp b/unit-test/rpc/test_communicator.cpp index f4b2db97..b1bf7b91 100755 --- a/unit-test/rpc/test_communicator.cpp +++ b/unit-test/rpc/test_communicator.cpp @@ -277,7 +277,7 @@ TEST_F(HelloTest, testNotifyCtrlC) HelloServer server; startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) 0); - HelloPrx prx = getObj(server.getCommunicator(), "HelloAdapter"); + HelloPrx prx = getObj(server.getApplicationCommunicator(), "HelloAdapter"); for(int i = 0; i < 10000; i++) { diff --git a/unit-test/rpc/test_dyeing.cpp b/unit-test/rpc/test_dyeing.cpp index 67cd504d..5dcb15f6 100755 --- a/unit-test/rpc/test_dyeing.cpp +++ b/unit-test/rpc/test_dyeing.cpp @@ -16,8 +16,10 @@ #include "hello_test.h" #include "servant/AdminF.h" -#include "server/FrameworkServer.h" -#include "server/framework/DbHandle.h" +//#include "server/FrameworkServer.h" +//#include "server/framework/DbHandle.h" +#include "mock/TarsMockUtil.h" +#include "mock/DbHandle.h" #define DYEFILEPATH (string("tars_dyeing") + FILE_SEP) @@ -52,11 +54,11 @@ TEST_F(HelloTest, DyeingNo) HelloServer server; startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) 0); - HelloPrx prx = getObj(server.getCommunicator().get(), "HelloAdapter"); + HelloPrx prx = getObj(server.getApplicationCommunicator().get(), "HelloAdapter"); // int64_t tBegin = TC_TimeProvider::getInstance()->getNowMs(); -// HelloPrx dyeingPrx= server.getCommunicator()->stringToProxy(DYEING_SERVANT_ENDPOINT); +// HelloPrx dyeingPrx= server.getApplicationCommunicator()->stringToProxy(DYEING_SERVANT_ENDPOINT); string strIn="123456"; string strOut; int ret=prx->testDyeing(strIn,strOut); @@ -70,26 +72,28 @@ TEST_F(HelloTest, DyeingNo) //打开染色开关,但未使用染色key调用的场景 TEST_F(HelloTest, DyeingNoKey) { - FrameworkServer fs; - startServer(fs, FRAMEWORK_CONFIG()); + TarsMockUtil tarsMockUtil; + tarsMockUtil.startFramework(); +// FrameworkServer fs; +// startServer(fs, FRAMEWORK_CONFIG()); - CDbHandle::cleanEndPoint(); - CDbHandle::addActiveEndPoint("TestApp.FrameworkServer.LogObj", 11005, 1); +// CDbHandle::cleanEndPoint(); +// CDbHandle::addActiveEndPoint("tars.tarsmock.LogObj", "127.0.0.1", 11005, 1); HelloServer server; startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) 0); // int64_t tBegin = TC_TimeProvider::getInstance()->getNowMs(); - AdminFPrx adminFPrx = server.getCommunicator()->stringToProxy("AdminObj@" + getLocalEndpoint(CONFIG()).toString()); + AdminFPrx adminFPrx = server.getApplicationCommunicator()->stringToProxy("AdminObj@" + getLocalEndpoint(CONFIG()).toString()); -// AdminFPrx adminFPrx = server.getCommunicator()->stringToProxy(UNIT_TEST_ADMIN_NAME_ENDPOINT); +// AdminFPrx adminFPrx = server.getApplicationCommunicator()->stringToProxy(UNIT_TEST_ADMIN_NAME_ENDPOINT); string setdyeing = adminFPrx->notify("tars.setdyeing 123456 TestApp.HelloServer.HelloObj testDyeing"); EXPECT_TRUE(setdyeing.find("DyeingKey=123456") != string::npos); - HelloPrx prx = getObj(server.getCommunicator().get(), "HelloAdapter"); + HelloPrx prx = getObj(server.getApplicationCommunicator().get(), "HelloAdapter"); -// DyeingTestPrx dyeingPrx= server.getCommunicator()->stringToProxy(DYEING_SERVANT_ENDPOINT); +// DyeingTestPrx dyeingPrx= server.getApplicationCommunicator()->stringToProxy(DYEING_SERVANT_ENDPOINT); string strIn="abc"; string strOut; int ret=prx->testDyeing(strIn,strOut); @@ -99,29 +103,31 @@ TEST_F(HelloTest, DyeingNoKey) // TLOGDEBUG("dyeing without key request time cost: "<< " | " << TC_TimeProvider::getInstance()->getNowMs() - tBegin << "(ms)" << endl); stopServer(server); - stopServer(fs); + tarsMockUtil.stopFramework(); +// stopServer(fs); } //打开染色开关,使用染色key调用的场景 TEST_F(HelloTest, DyeingKey) { - FrameworkServer fs; - startServer(fs, FRAMEWORK_CONFIG()); + TarsMockUtil tarsMockUtil; +// FrameworkServer fs; +// startServer(fs, FRAMEWORK_CONFIG()); - CDbHandle::cleanEndPoint(); - CDbHandle::addActiveEndPoint("TestApp.FrameworkServer.LogObj", 11005, 1); +// CDbHandle::cleanEndPoint(); +// CDbHandle::addActiveEndPoint("tars.tarsmock.LogObj", "127.0.0.1", 11005, 1); HelloServer server; startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) 0); - AdminFPrx adminFPrx = server.getCommunicator()->stringToProxy("AdminObj@" + getLocalEndpoint(CONFIG()).toString()); + AdminFPrx adminFPrx = server.getApplicationCommunicator()->stringToProxy("AdminObj@" + getLocalEndpoint(CONFIG()).toString()); string setdyeing = adminFPrx->notify("tars.setdyeing 123456 TestApp.HelloServer.HelloObj testDyeing"); EXPECT_TRUE(setdyeing.find("DyeingKey=123456") != string::npos); TC_File::removeFile("./tars_dyeing", true); - HelloPrx prx = getObj(server.getCommunicator().get(), "HelloAdapter"); + HelloPrx prx = getObj(server.getApplicationCommunicator().get(), "HelloAdapter"); string strIn="123456"; string strOut; @@ -138,7 +144,8 @@ TEST_F(HelloTest, DyeingKey) EXPECT_EQ(getFileLine(dyeDebugFile.c_str()), 4); stopServer(server); - stopServer(fs); + tarsMockUtil.stopFramework(); +// stopServer(fs); } diff --git a/unit-test/rpc/test_proxy_timeout.cpp b/unit-test/rpc/test_proxy_timeout.cpp index 89225b81..8b9e938b 100755 --- a/unit-test/rpc/test_proxy_timeout.cpp +++ b/unit-test/rpc/test_proxy_timeout.cpp @@ -10,28 +10,22 @@ TEST_F(HelloTest, proxyInvokeTimeout) checkSyncTimeout(comm); }, c.get()); - LOG_CONSOLE_DEBUG << endl; - transInCoroutineGlobalCommunicator([&](Communicator *comm){ checkSyncTimeout(comm); }, c.get()); - LOG_CONSOLE_DEBUG << endl; transServerCommunicator([&](Communicator *comm){ checkSyncTimeout(comm); }); - LOG_CONSOLE_DEBUG << endl; transInCoroutineServerCommunicator([&](Communicator *comm){ checkSyncTimeout(comm); }); - LOG_CONSOLE_DEBUG << endl; transAllocCommunicator([&](Communicator *comm){ checkSyncTimeout(comm); }); - LOG_CONSOLE_DEBUG << endl; transInCoroutineAllocCommunicator([&](Communicator *comm){ checkSyncTimeout(comm); }); diff --git a/unit-test/rpc/test_prx_update.cpp b/unit-test/rpc/test_prx_update.cpp index fb4ccea5..07cf2861 100755 --- a/unit-test/rpc/test_prx_update.cpp +++ b/unit-test/rpc/test_prx_update.cpp @@ -2,8 +2,8 @@ #include "hello_test.h" #include "servant/CommunicatorEpoll.h" #include "servant/ObjectProxy.h" -#include "server/framework/DbHandle.h" -#include "server/FrameworkServer.h" +//#include "server/framework/DbHandle.h" +#include "server/RpcServer.h" #include "QueryF.h" TEST_F(HelloTest, prxUpdate) diff --git a/unit-test/rpc/test_push.cpp b/unit-test/rpc/test_push.cpp index 62f7db0e..8c7848b0 100755 --- a/unit-test/rpc/test_push.cpp +++ b/unit-test/rpc/test_push.cpp @@ -46,7 +46,7 @@ class RegisterPushCallBack : public PushPrxCallback bool _close = false; }; -typedef TC_AutoPtr RegisterPushCallBackPtr; +//typedef TC_AutoPtr RegisterPushCallBackPtr; TEST_F(HelloTest, push) { @@ -59,7 +59,7 @@ TEST_F(HelloTest, push) HelloPrx prx = comm->stringToProxy(obj); - RegisterPushCallBackPtr callback = new RegisterPushCallBack(); + ServantProxyCallbackPtr callback(new RegisterPushCallBack()); prx->tars_set_push_callback(callback); @@ -69,7 +69,7 @@ TEST_F(HelloTest, push) TC_Common::msleep(50); - ASSERT_TRUE(callback->_msg == msg); + ASSERT_TRUE(((RegisterPushCallBack*)callback.get())->_msg == msg); stopServer(ws); } @@ -86,7 +86,7 @@ TEST_F(HelloTest, pushClose) HelloPrx prx = comm->stringToProxy(obj); - RegisterPushCallBackPtr callback = new RegisterPushCallBack(); + ServantProxyCallbackPtr callback(new RegisterPushCallBack); prx->tars_set_push_callback(callback); @@ -96,13 +96,13 @@ TEST_F(HelloTest, pushClose) TC_Common::msleep(50); - ASSERT_TRUE(callback->_msg == msg); + ASSERT_TRUE(((RegisterPushCallBack*)callback.get())->_msg == msg); prx->tars_close(); TC_Common::msleep(50); - ASSERT_TRUE(callback->_close); + ASSERT_TRUE(((RegisterPushCallBack*)callback.get())->_close); stopServer(ws); } diff --git a/unit-test/rpc/test_registry.cpp b/unit-test/rpc/test_registry.cpp index a8f9fbda..a407ce5e 100755 --- a/unit-test/rpc/test_registry.cpp +++ b/unit-test/rpc/test_registry.cpp @@ -2,9 +2,10 @@ #include "hello_test.h" #include "servant/CommunicatorEpoll.h" #include "servant/ObjectProxy.h" -#include "server/framework/DbHandle.h" -#include "server/FrameworkServer.h" +#include "mock/DbHandle.h" +#include "mock/TarsMockUtil.h" #include "QueryF.h" +#include "server/RpcServer.h" TEST_F(HelloTest, registryQuery) { @@ -17,11 +18,13 @@ TEST_F(HelloTest, registryQuery) TC_Config fconf = FRAMEWORK_CONFIG(); CDbHandle::cleanEndPoint(); - CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9990, 1); - CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9991, 1); + CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9990, 1); + CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9991, 1); - FrameworkServer fs; - startServer(fs, FRAMEWORK_CONFIG()); + TarsMockUtil tarsMockUtil; + tarsMockUtil.startFramework(); +// FrameworkServer fs; +// startServer(fs, FRAMEWORK_CONFIG()); string obj = getObj(fconf, "RegistryAdapter"); @@ -36,7 +39,7 @@ TEST_F(HelloTest, registryQuery) } { - CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1); + CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9992, 1); TC_Common::sleep(6); @@ -55,7 +58,7 @@ TEST_F(HelloTest, registryQuery) } { - CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9993, 1); + CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9993, 1); TC_Common::sleep(6); @@ -74,16 +77,17 @@ TEST_F(HelloTest, registryQuery) } } - stopServer(fs); + tarsMockUtil.stopFramework(); +// stopServer(fs); } #define START_FRAMEWORK_SERVER_1_2 \ CDbHandle::cleanEndPoint(); \ -CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9990, 1); \ -CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9991, 1); \ -FrameworkServer fs; \ -startServer(fs, FRAMEWORK_CONFIG()); \ +CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9990, 1); \ +CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9991, 1); \ +TarsMockUtil tarsMockUtil; \ +tarsMockUtil.startFramework(); \ RpcServer rpc1Server; \ startServer(rpc1Server, RPC1_CONFIG()); \ RpcServer rpc2Server; \ @@ -92,16 +96,16 @@ startServer(rpc2Server, RPC2_CONFIG()); #define START_FRAMEWORK_HTTP_SERVER_1_2 \ CDbHandle::cleanEndPoint(); \ -CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", 8180, 1); \ -CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", 8181, 1); \ -FrameworkServer fs; \ -startServer(fs, FRAMEWORK_CONFIG()); \ +CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", "127.0.0.1", 8180, 1); \ +CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", "127.0.0.1", 8181, 1); \ +TarsMockUtil tarsMockUtil; \ +tarsMockUtil.startFramework(); \ RpcServer rpc1Server; \ startServer(rpc1Server, RPC1_CONFIG()); \ RpcServer rpc2Server; \ startServer(rpc2Server, RPC2_CONFIG()); -#define STOP_FRAMEWORK_SERVER stopServer(fs); +#define STOP_FRAMEWORK_SERVER tarsMockUtil.stopFramework(); #define HELLO_CALL {\ HelloPrx qPrx = comm->stringToProxy("TestApp.RpcServer.HelloObj"); \ @@ -114,7 +118,7 @@ ASSERT_TRUE(out == _buffer); } #define CHECK_REGISTRY_UPDATE {\ stopServer(rpc1Server); \ CDbHandle::cleanEndPoint(); \ -CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1); \ +CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9992, 1); \ RpcServer rpc3Server; \ startServer(rpc3Server, RPC3_CONFIG()); \ wait(6000); \ @@ -188,7 +192,8 @@ TEST_F(HelloTest, registryRpc) LOG_CONSOLE_DEBUG << endl; stopServer(rpc1Server); stopServer(rpc2Server); - stopServer(fs); + tarsMockUtil.stopFramework(); +// stopServer(fs); } @@ -196,8 +201,8 @@ TEST_F(HelloTest, registryRpc) TEST_F(HelloTest, registryRpcConHashInvoke) { START_FRAMEWORK_SERVER_1_2 - CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9989, 1); - CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1); + CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9989, 1); + CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj","127.0.0.1", 9992, 1); shared_ptr c = getCommunicator(); @@ -330,7 +335,7 @@ TEST_F(HelloTest, registryRpcCheckUpdateList) //更新主控ip list CDbHandle::cleanEndPoint(); - CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1); + CDbHandle::addActiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9992, 1); RpcServer rpc3Server; startServer(rpc3Server, RPC3_CONFIG()); @@ -430,7 +435,7 @@ TEST_F(HelloTest, registryHttpRpcCheckUpdateList) //更新主控ip list CDbHandle::cleanEndPoint(); - CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", 8182, 1); + CDbHandle::addActiveEndPoint("TestApp.RpcServer.HttpObj", "127.0.0.1", 8182, 1); RpcServer rpc3Server; startServer(rpc3Server, RPC3_CONFIG()); @@ -471,8 +476,8 @@ TEST_F(HelloTest, registryHttpRpcCheckUpdateList) TEST_F(HelloTest, registryRpcHashTagInvoke) { START_FRAMEWORK_SERVER_1_2 - CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9989, 1); - CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1); + CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9989, 1); + CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9992, 1); shared_ptr c = getCommunicator(); @@ -495,8 +500,8 @@ TEST_F(HelloTest, registryRpcHashTagInvoke) TEST_F(HelloTest, registryRpcMultiHashTagInvoke) { START_FRAMEWORK_SERVER_1_2 - CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9989, 1); - CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", 9992, 1); + CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9989, 1); + CDbHandle::addInactiveEndPoint("TestApp.RpcServer.HelloObj", "127.0.0.1", 9992, 1); shared_ptr c = getCommunicator(); diff --git a/unit-test/rpc/test_stat.cpp b/unit-test/rpc/test_stat.cpp index 200b94d9..94ee7a98 100755 --- a/unit-test/rpc/test_stat.cpp +++ b/unit-test/rpc/test_stat.cpp @@ -1,6 +1,6 @@  #include "hello_test.h" -#include "server/FrameworkServer.h" +#include "mock/TarsMockUtil.h" int getStatCount(const vector> &data) { @@ -21,8 +21,10 @@ int getStatCount(const vector> & TEST_F(HelloTest, statReport) { - FrameworkServer fs; - startServer(fs, FRAMEWORK_CONFIG()); + TarsMockUtil tarsMockUtil; + tarsMockUtil.startFramework(); +// FrameworkServer fs; +// startServer(fs, FRAMEWORK_CONFIG()); HelloServer hs; startServer(hs, CONFIG()); @@ -62,14 +64,15 @@ TEST_F(HelloTest, statReport) // LOG_CONSOLE_DEBUG << "server stat:" << _serverStatData.size() << endl; stopServer(hs); - stopServer(fs); + tarsMockUtil.stopFramework(); +// stopServer(fs); } TEST_F(HelloTest, statReportInCoroutine) { - FrameworkServer fs; - startServer(fs, FRAMEWORK_CONFIG()); + TarsMockUtil tarsMockUtil; + tarsMockUtil.startFramework(); HelloServer hs; startServer(hs, CONFIG()); @@ -110,5 +113,5 @@ TEST_F(HelloTest, statReportInCoroutine) }, true); stopServer(hs); - stopServer(fs); + tarsMockUtil.stopFramework(); } \ No newline at end of file diff --git a/unit-test/rpc/test_trans.cpp b/unit-test/rpc/test_trans.cpp index 97b3180d..0868fc7b 100755 --- a/unit-test/rpc/test_trans.cpp +++ b/unit-test/rpc/test_trans.cpp @@ -1,7 +1,7 @@  #include "hello_test.h" -TEST_F(HelloTest, rpcTransGlobalCommunicator) +TEST_F(HelloTest, transGlobalCommunicator) { shared_ptr c = getCommunicator(); @@ -22,7 +22,7 @@ TEST_F(HelloTest, rpcTransGlobalCommunicator) }, c.get()); } -TEST_F(HelloTest, rpcTransGlobalCommunicatorInCoroutine) +TEST_F(HelloTest, transGlobalCommunicatorInCoroutine) { shared_ptr c = getCommunicator(); @@ -43,7 +43,7 @@ TEST_F(HelloTest, rpcTransGlobalCommunicatorInCoroutine) }, c.get()); } -TEST_F(HelloTest, rpcTransServerCommunicator) +TEST_F(HelloTest, transServerCommunicator) { transServerCommunicator([&](Communicator *comm){ checkTransSyncASync(comm); @@ -62,7 +62,7 @@ TEST_F(HelloTest, rpcTransServerCommunicator) }); } -TEST_F(HelloTest, rpcTransServerCommunicatorInCoroutine) +TEST_F(HelloTest, transServerCommunicatorInCoroutine) { transInCoroutineServerCommunicator([&](Communicator *comm){ checkTransSyncASync(comm); @@ -81,7 +81,7 @@ TEST_F(HelloTest, rpcTransServerCommunicatorInCoroutine) }); } -TEST_F(HelloTest, rpcTransAllocCommunicator) +TEST_F(HelloTest, transAllocCommunicator) { transAllocCommunicator([&](Communicator *comm){ checkTransSyncASync(comm); @@ -100,7 +100,7 @@ TEST_F(HelloTest, rpcTransAllocCommunicator) }); } -TEST_F(HelloTest, rpcTransAllocCommunicatorInCoroutine) +TEST_F(HelloTest, transAllocCommunicatorInCoroutine) { transInCoroutineAllocCommunicator([&](Communicator *comm){ checkTransSyncASync(comm); @@ -120,7 +120,7 @@ TEST_F(HelloTest, rpcTransAllocCommunicatorInCoroutine) } -TEST_F(HelloTest, rpcTransComplexCommunicator) +TEST_F(HelloTest, transComplexCommunicator) { shared_ptr c = getCommunicator(); @@ -142,7 +142,7 @@ TEST_F(HelloTest, rpcTransComplexCommunicator) } -TEST_F(HelloTest, rpcTransComplexCommunicatorInCoroutine) +TEST_F(HelloTest, transComplexCommunicatorInCoroutine) { shared_ptr c = getCommunicator(); diff --git a/unit-test/rpc/test_win_server.cpp b/unit-test/rpc/test_win_server.cpp index 7a9591cc..f6a03a3e 100644 --- a/unit-test/rpc/test_win_server.cpp +++ b/unit-test/rpc/test_win_server.cpp @@ -1,7 +1,9 @@  #include "hello_test.h" #include "../server/WinServer.h" - +#include "mock/TarsMockUtil.h" +#include "mock/DbHandle.h" +#include "mock/ConfigImp.h" TEST_F(HelloTest, winServerInCoroutine) @@ -107,8 +109,8 @@ TEST_F(HelloTest, winServerAsync) //发起远程调用 for (int j = 0; j < _count; ++j) { - HelloPrxCallbackPtr p = new ClientHelloCallback(TC_Common::now2us(), j, _count, _buffer, - callback_count); + HelloPrxCallbackPtr p(new ClientHelloCallback(TC_Common::now2us(), j, _count, _buffer, + callback_count)); prx->async_testHello(p, j, _buffer); } @@ -360,3 +362,70 @@ TEST_F(HelloTest, winServerHashTag) stopServer(ws); } + +TEST_F(HelloTest, winServerConfig) +{ + TC_File::removeFile("./test.conf", true); + TC_File::removeFile("./test.conf.1.bak", true); + TC_File::removeFile("./test.conf.2.bak", true); + TC_File::removeFile("./test.conf.3.bak", true); + TC_File::removeFile("./test.conf.4.bak", true); + TC_File::removeFile("./tarsmock.tarsdat", true); + + TarsMockUtil tarsMockUtil; + tarsMockUtil.startFramework(); + + ConfigImp::setConfigFile("test.conf", "test-content"); + +// FrameworkServer fs; +// startServer(fs, FRAMEWORK_CONFIG()); + + { + WinServer ws; + + startServer(ws, WIN_CONFIG(), TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD); + + ASSERT_TRUE(!TC_File::isFileExist("./test.conf")); + + stopServer(ws); + } + +// CDbHandle::addActiveEndPoint("tars.tarsmock.ConfigObj", "127.0.0.1", 11003, 1); + { + WinServer ws; + + startServer(ws, WIN_CONFIG(), TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD); + + ASSERT_TRUE(TC_File::isFileExist("./test.conf")); + + stopServer(ws); + } + + CDbHandle::cleanEndPoint(); + + { + WinServer ws; + + startServer(ws, WIN_CONFIG(), TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD); + + ASSERT_TRUE(TC_File::isFileExist("./test.conf")); + + stopServer(ws); + } + + ConfigImp::setConfigFile("test.conf", "content"); + { + WinServer ws; + + startServer(ws, WIN_CONFIG(), TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD); + + ASSERT_TRUE(TC_File::isFileExist("./test.conf")); + ASSERT_TRUE(TC_File::isFileExist("./test.conf.1.bak")); + EXPECT_EQ(TC_File::load2str("./test.conf"), "content"); + + stopServer(ws); + } +// stopServer(fs); + tarsMockUtil.stopFramework(); +} + diff --git a/unit-test/rpc/test_wup_trans.cpp b/unit-test/rpc/test_wup_trans.cpp index c1f2e25c..b49339d1 100755 --- a/unit-test/rpc/test_wup_trans.cpp +++ b/unit-test/rpc/test_wup_trans.cpp @@ -1,7 +1,7 @@  #include "hello_test.h" -TEST_F(HelloTest, rpcWupTransGlobalCommunicator) +TEST_F(HelloTest, wupTransGlobalCommunicator) { shared_ptr c = getCommunicator(); @@ -10,7 +10,7 @@ TEST_F(HelloTest, rpcWupTransGlobalCommunicator) }, c.get()); } -TEST_F(HelloTest, rpcWupTransGlobalCommunicatorInCoroutine) +TEST_F(HelloTest, wupTransGlobalCommunicatorInCoroutine) { shared_ptr c = getCommunicator(); @@ -20,7 +20,7 @@ TEST_F(HelloTest, rpcWupTransGlobalCommunicatorInCoroutine) } -TEST_F(HelloTest, rpcWupTransServerCommunicator) +TEST_F(HelloTest, wupTransServerCommunicator) { transServerCommunicator([&](Communicator *comm){ checkWupTransSync(comm); diff --git a/unit-test/server/FrameworkServer.cpp b/unit-test/server/FrameworkServer.cpp deleted file mode 100755 index 867be4e9..00000000 --- a/unit-test/server/FrameworkServer.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include "FrameworkServer.h" -#include "framework/ConfigImp.h" -#include "framework/QueryImp.h" -#include "framework/StatImp.h" -#include "framework/LogImp.h" - -#include "HttpImp.h" -#include "HelloImp.h" - -using namespace std; - -vector> _clientStatData; -vector> _serverStatData; - -FrameworkServer::~FrameworkServer() -{ - -} - - -void -FrameworkServer::initialize() -{ - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".ConfigObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".QueryObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".StatObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".LogObj"); - - string s; - loadLogFormat("","",s); - - //日志路径 - g_globe._log_path = _conf["/tars/log"]; - - //启动写线程 - g_globe._group.start(TC_Common::strto(_conf["/tars/log"])); - - string prefix = TC_Common::lower(_conf.get("/tars/log","true")); - g_globe._bIpPrefix = (prefix == "true") ? true : false; - - //增加对象 - addServant(ServerConfig::Application + "." + ServerConfig::ServerName +".LogObj"); - - TARS_ADD_ADMIN_CMD_NORMAL("reloadLogFormat", FrameworkServer::loadLogFormat); -} - - -bool FrameworkServer::loadLogFormat(const string& command, const string& params, string& result) -{ - TLOGDEBUG("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << endl); - - try - { - TC_Config conf; - - conf.parseFile(ServerConfig::ConfigFile); - - vector vHourlist; - - map mLogType; - - try - { - string sHour = conf["/tars/log/format"]; - - vHourlist = TC_Common::sepstr(sHour,"|;,"); - - sort(vHourlist.begin(),vHourlist.end()); - - unique(vHourlist.begin(),vHourlist.end()); - - result = "loadLogFormat succ:" + sHour; - - TLOGDEBUG("FrameworkServer::loadLogFormat result:" << result << endl); - - DLOG<< "FrameworkServer::loadLogFormat result:" << result << endl; - - //hour=app.server.file|app2.server2.file2 - map mType; - if(conf.getDomainMap("/tars/log/logtype", mType)) - { - map::iterator it = mType.begin(); - while(it != mType.end()) - { - vector vList = TC_Common::sepstr(it->second,"|;,"); - for(size_t i = 0;i < vList.size();i++) - { - //app.server.file = hour - mLogType[vList[i]] = it->first; - - TLOGDEBUG("FrameworkServer::loadLogFormat " << vList[i] << "|" << it->first << endl); - - DLOG<<"FrameworkServer::loadLogFormat " << vList[i] << "|" << it->first << endl; - } - it++; - } - } - - g_globe.update(vHourlist, mLogType); - - } - catch(exception& e) - { - result += e.what(); - TLOGERROR("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << "|result:" << result << endl); - } - - return true; - } - catch(exception &e) - { - result += e.what(); - TLOGERROR("FrameworkServer::loadLogFormat command:" << command << "|params:" << params << "|result:" << result << endl); - } - - return false; -} - -void FrameworkServer::destroyApp() -{ -} - -void FrameworkServer::run() -{ - this->waitForShutdown(); -} -///////////////////////////////////////////////////////////////// - -RpcServer::~RpcServer() -{ - -} - - -void -RpcServer::initialize() -{ - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".HelloObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpObj"); - addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpObj", &TC_NetWorkBuffer::parseHttp); - -} - -///////////////////////////////////////////////////////////////// -void RpcServer::destroyApp() -{ -} - -void RpcServer::run() -{ - this->waitForShutdown(); -} \ No newline at end of file diff --git a/unit-test/server/FrameworkServer.h b/unit-test/server/FrameworkServer.h deleted file mode 100755 index 5d6a95e0..00000000 --- a/unit-test/server/FrameworkServer.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef _FrameworkServer_H_ -#define _FrameworkServer_H_ - -#include -#include "servant/Application.h" - -using namespace tars; - -extern vector> _clientStatData; -extern vector> _serverStatData; - -class FrameworkServer : public Application, public TC_Thread -{ -public: - /** - * 析构函数 - **/ - virtual ~FrameworkServer(); - - /** - * 服务初始化 - **/ - virtual void initialize(); - - /** - * 服务销毁 - **/ - virtual void destroyApp(); - -protected: - virtual void run(); - - bool loadLogFormat(const string& command, const string& params, string& result); - -}; - -class RpcServer : public Application, public TC_Thread -{ -public: - /** - * 析构函数 - **/ - virtual ~RpcServer(); - - /** - * 服务初始化 - **/ - virtual void initialize(); - - /** - * 服务销毁 - **/ - virtual void destroyApp(); - -protected: - virtual void run(); - -}; - - -//////////////////////////////////////////// -#endif diff --git a/unit-test/server/HelloImp.cpp b/unit-test/server/HelloImp.cpp index 3f599d7b..8e17e0ad 100755 --- a/unit-test/server/HelloImp.cpp +++ b/unit-test/server/HelloImp.cpp @@ -61,7 +61,7 @@ int HelloImp::testTrans(int index, const string &s, string &r, CurrentPtr curren { current->setResponse(false); - HelloPrxCallbackPtr p = new HelloCallback(current, index, s); + HelloPrxCallbackPtr p(new HelloCallback(current, index, s)); _helloPrx->async_testHello(p, index, s); } @@ -150,7 +150,7 @@ bool HelloImp::testCoro(const std::string& sIn, std::string &sOut, CurrentPtr cu int HelloImp::testConHash(std::string &sOut, CurrentPtr current) { - sOut = _handle->getBindAdapter()->getEndpoint().toString(); + sOut = getHandle()->getBindAdapter()->getEndpoint().toString(); return 0; } diff --git a/unit-test/server/HelloServer.cpp b/unit-test/server/HelloServer.cpp index 0618904f..c565d071 100755 --- a/unit-test/server/HelloServer.cpp +++ b/unit-test/server/HelloServer.cpp @@ -55,42 +55,42 @@ HelloServer::initialize() { // this->_epollServer->setUdpRecvBufferSize(10 * 1024 * 1024); // this->_epollServer->setUdpSendBufferSize(10 * 1024 * 1024); - g_HelloServerObj = ServerConfig::Application + "." + ServerConfig::ServerName +".HelloObj@" + getEpollServer()->getBindAdapter("HelloAdapter")->getEndpoint().toString(); - g_TransDstServerObj = ServerConfig::Application + "." + ServerConfig::ServerName +".TransDstObj@" + getEpollServer()->getBindAdapter("TransDstAdapter")->getEndpoint().toString(); + g_HelloServerObj =_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HelloObj@" + getEpollServer()->getBindAdapter("HelloAdapter")->getEndpoint().toString(); + g_TransDstServerObj =_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".TransDstObj@" + getEpollServer()->getBindAdapter("TransDstAdapter")->getEndpoint().toString(); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName +".HelloObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName +".TransObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName +".HelloTimeoutObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName +".HelloNoTimeoutObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HelloObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".TransObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HelloTimeoutObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HelloNoTimeoutObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName +".Ipv6Obj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".Ipv6Obj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName +".HttpObj"); - addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpObj", &TC_NetWorkBuffer::parseHttp); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName +".HttpsObj"); - addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".HttpsObj", &TC_NetWorkBuffer::parseHttp); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HttpObj"); + addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HttpObj", &TC_NetWorkBuffer::parseHttp); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".HttpsObj"); + addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HttpsObj", &TC_NetWorkBuffer::parseHttp); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName +".TransDstObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".TransDstObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName +".TransWupObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".TransWupObj"); //设置服务的协议解析器, 对服务器端而言, 解析器的目的就是识别包长度 //parseStream,表示第0个字节开始,类型是uint32_t, 字节序, 这个字段表示包的长度 TC_NetWorkBuffer::protocol_functor func = AppProtocol::parseStream<0, uint32_t, true>; - addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName +".TransWupObj", func); + addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName +".TransWupObj", func); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".CustomObj"); - addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".CustomObj", parse); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".CustomObj"); + addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".CustomObj", parse); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".SSLObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".SSL1Obj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".SSL2Obj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".SSL3Obj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".AuthObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".UdpObj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".UdpIpv6Obj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".SSLObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".SSL1Obj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".SSL2Obj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".SSL3Obj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".AuthObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".UdpObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".UdpIpv6Obj"); - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".PushObj"); - addServantProtocol(ServerConfig::Application + "." + ServerConfig::ServerName + ".PushObj", parse); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".PushObj"); + addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".PushObj", parse); pushThread = new PushInfoThread(); pushThread->start(); diff --git a/unit-test/server/RpcServer.cpp b/unit-test/server/RpcServer.cpp new file mode 100644 index 00000000..105ee8d7 --- /dev/null +++ b/unit-test/server/RpcServer.cpp @@ -0,0 +1,32 @@ +// +// Created by jarod on 2024/3/14. +// + +#include "RpcServer.h" +#include "HelloImp.h" +#include "HttpImp.h" + +RpcServer::~RpcServer() +{ + +} + + +void +RpcServer::initialize() +{ + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HelloObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HttpObj"); + addServantProtocol(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".HttpObj", &TC_NetWorkBuffer::parseHttp); + +} + +///////////////////////////////////////////////////////////////// +void RpcServer::destroyApp() +{ +} + +void RpcServer::run() +{ + this->waitForShutdown(); +} \ No newline at end of file diff --git a/unit-test/server/RpcServer.h b/unit-test/server/RpcServer.h new file mode 100644 index 00000000..debf5799 --- /dev/null +++ b/unit-test/server/RpcServer.h @@ -0,0 +1,32 @@ +// +// Created by jarod on 2024/3/14. +// + +#pragma once +#include +#include "servant/Application.h" + +using namespace tars; + +class RpcServer : public Application, public TC_Thread +{ +public: + /** + * 析构函数 + **/ + virtual ~RpcServer(); + + /** + * 服务初始化 + **/ + virtual void initialize(); + + /** + * 服务销毁 + **/ + virtual void destroyApp(); + +protected: + virtual void run(); + +}; diff --git a/unit-test/server/TranImp.cpp b/unit-test/server/TranImp.cpp index f36d7a0e..4fd56ab7 100755 --- a/unit-test/server/TranImp.cpp +++ b/unit-test/server/TranImp.cpp @@ -32,7 +32,7 @@ void TranImp::async_call(tars::CurrentPtr current, vector &response) TLOGDEBUG("async_call: begin remote call, req len:" << req.sBuffer.size() << endl); /*a-sync-call*/ - ServantProxyCallbackPtr cb = new ServantCallback("ServantCallback", this, current); + ServantProxyCallbackPtr cb(new ServantCallback("ServantCallback", this, current)); _servantPrx->rpc_call_async(req.iRequestId, req.sFuncName, request.data(), request.size(), cb); current->setResponse(false); } diff --git a/unit-test/server/WinServer.cpp b/unit-test/server/WinServer.cpp index 74b18fb7..b99090fe 100644 --- a/unit-test/server/WinServer.cpp +++ b/unit-test/server/WinServer.cpp @@ -13,8 +13,9 @@ WinServer::~WinServer() void WinServer::initialize() { - addServant(ServerConfig::Application + "." + ServerConfig::ServerName + ".WinObj"); + addServant(_serverBaseInfo.Application + "." + _serverBaseInfo.ServerName + ".WinObj"); + addConfig("test.conf"); TARS_ADD_ADMIN_CMD_NORMAL("AdminCmdNormalTest", WinServer::cmdAdd); TARS_ADD_ADMIN_CMD_NORMAL("CmdToDelete", WinServer::cmdAdd); diff --git a/unit-test/server/client.conf b/unit-test/server/client.conf index df0fb2ce..8b8045fb 100755 --- a/unit-test/server/client.conf +++ b/unit-test/server/client.conf @@ -3,13 +3,13 @@ #tarsregistry locator - locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004 + locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890 sync-invoke-timeout = 50000 async-invoke-timeout = 50000 #refresh endpoint interval refresh-endpoint-interval = 3000 #stat obj - stat = TestApp.FrameworkServer.StatObj@tcp -h 127.0.0.1 -p 12004 + stat = tars.tarsmock.StatObj@tcp -h 127.0.0.1 -p 12004 #max send queue length limit sendqueuelimit = 1000000 #async queue length limit diff --git a/unit-test/server/hello.conf b/unit-test/server/hello.conf index 063886fc..4a175ab2 100755 --- a/unit-test/server/hello.conf +++ b/unit-test/server/hello.conf @@ -3,14 +3,14 @@ #proxy需要的配置 #地址 - locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004 + locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890 #最大超时时间(毫秒) sync-invoke-timeout = 50000 async-invoke-timeout = 60000 #刷新端口时间间隔(毫秒) refresh-endpoint-interval = 100000 #模块间调用[可选] - stat = TestApp.FrameworkServer.StatObj + stat = tars.tarsmock.StatObj #发送队列长度 sendqueuelimit = 1000000 #异步回调队列个数限制 @@ -95,11 +95,11 @@ local = tcp -h 127.0.0.1 -p 18001 -t 10000 #配置中心的地址[可选] - config = TestApp.FrameworkServer.ConfigObj + config = tars.tarsmock.ConfigObj #配置中心的地址[可选] # notify = tars.tarsconfig.NotifyObj #远程LogServer[可选] - log = TestApp.FrameworkServer.LogObj + log = tars.tarsmock.LogObj # manuallisten = 1 diff --git a/unit-test/server/rpc1.conf b/unit-test/server/rpc1.conf index 3c145946..54ad56f0 100755 --- a/unit-test/server/rpc1.conf +++ b/unit-test/server/rpc1.conf @@ -3,7 +3,7 @@ #proxy需要的配置 #地址 - locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004 + locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890 #最大超时时间(毫秒) sync-invoke-timeout = 5000 async-invoke-timeout = 60000 diff --git a/unit-test/server/rpc2.conf b/unit-test/server/rpc2.conf index 0b34ca9e..5965f08e 100755 --- a/unit-test/server/rpc2.conf +++ b/unit-test/server/rpc2.conf @@ -3,7 +3,7 @@ #proxy需要的配置 #地址 - locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004 + locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890 #最大超时时间(毫秒) sync-invoke-timeout = 5000 async-invoke-timeout = 60000 diff --git a/unit-test/server/rpc3.conf b/unit-test/server/rpc3.conf index 715dd241..45dc4949 100755 --- a/unit-test/server/rpc3.conf +++ b/unit-test/server/rpc3.conf @@ -3,7 +3,7 @@ #proxy需要的配置 #地址 - locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004 + locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890 #最大超时时间(毫秒) sync-invoke-timeout = 5000 async-invoke-timeout = 60000 diff --git a/unit-test/server/windows.conf b/unit-test/server/windows.conf index c0cb9fc9..4cf97513 100644 --- a/unit-test/server/windows.conf +++ b/unit-test/server/windows.conf @@ -3,14 +3,14 @@ #proxy需要的配置 #地址 - locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004 + locator = tars.tarsmock.QueryObj@tcp -h 127.0.0.1 -p 17890 #最大超时时间(毫秒) sync-invoke-timeout = 15000 async-invoke-timeout = 60000 #刷新端口时间间隔(毫秒) refresh-endpoint-interval = 100000 #模块间调用[可选] - stat = TestApp.FrameworkServer.StatObj + stat = tars.tarsmock.StatObj #发送队列长度 sendqueuelimit = 1000000 #异步回调队列个数限制 @@ -19,8 +19,6 @@ asyncthread = 3 #网络线程个数 netthread = 1 - #合并回调线程和网络线程(以网络线程个数为准) - mergenetasync = 0 #模块名称 modulename = TestApp.WinServer @@ -51,7 +49,7 @@ local = tcp -h 127.0.0.1 -p 15001 -t 10000 #配置中心的地址[可选] - config = TestApp.FrameworkServer.ConfigObj + config = tars.tarsmock.ConfigObj #配置中心的地址[可选] # notify = tars.tarsconfig.NotifyObj #远程LogServer[可选] diff --git a/unit-test/util/test_tc_endpoint.cpp b/unit-test/util/test_tc_endpoint.cpp index 37064218..a5c8e7cd 100644 --- a/unit-test/util/test_tc_endpoint.cpp +++ b/unit-test/util/test_tc_endpoint.cpp @@ -35,7 +35,7 @@ TEST_F(UtilEndpointTest, sep) vector eps = TC_Endpoint::sepEndpoint(str); - EXPECT_EQ(eps.size(), 1); + EXPECT_EQ(eps.size(), (size_t)1); EXPECT_EQ(eps[0], str); @@ -43,7 +43,7 @@ TEST_F(UtilEndpointTest, sep) eps = TC_Endpoint::sepEndpoint(str); - EXPECT_EQ(eps.size(), 1); + EXPECT_EQ(eps.size(), (size_t)1); EXPECT_EQ(eps[0], str); @@ -51,7 +51,7 @@ TEST_F(UtilEndpointTest, sep) eps = TC_Endpoint::sepEndpoint(str); - EXPECT_EQ(eps.size(), 1); + EXPECT_EQ(eps.size(), (size_t)1); EXPECT_EQ(eps[0], str); @@ -59,7 +59,7 @@ TEST_F(UtilEndpointTest, sep) eps = TC_Endpoint::sepEndpoint(str); - EXPECT_EQ(eps.size(), 1); + EXPECT_EQ(eps.size(), (size_t)1); EXPECT_EQ(eps[0], TC_Common::trim(str)); @@ -67,7 +67,7 @@ TEST_F(UtilEndpointTest, sep) eps = TC_Endpoint::sepEndpoint(str); - EXPECT_EQ(eps.size(), 1); + EXPECT_EQ(eps.size(), (size_t)1); EXPECT_EQ(eps[0], TC_Common::trim("tcp -h ::1 -p 25460 -t 60000")); } @@ -79,7 +79,7 @@ TEST_F(UtilEndpointTest, seps) vector eps = TC_Endpoint::sepEndpoint(str); - EXPECT_EQ(eps.size(), 3); + EXPECT_EQ(eps.size(), (size_t)3); EXPECT_EQ(eps[0], "udp -h ::1 -p 25460 -t 60000"); EXPECT_EQ(eps[1], "tcp -h 127.0.0.1 -p 25460 -t 60000"); diff --git a/unit-test/util/test_tc_file.cpp b/unit-test/util/test_tc_file.cpp index 68f404f4..7a75f856 100644 --- a/unit-test/util/test_tc_file.cpp +++ b/unit-test/util/test_tc_file.cpp @@ -150,3 +150,20 @@ TEST_F(UtilFileTest, config) ASSERT_TRUE(volumes.size() == 2); } + +TEST_F(UtilFileTest, join) +{ + string v1 = TC_File::joinPaths("abc", string("def"), string("ddd")); + + ASSERT_TRUE(v1 == string("abc") + FILE_SEP + "def" + FILE_SEP + "ddd"); + + string v2 = TC_File::joinPaths("abc/", string("def"), string("ddd")); + + ASSERT_TRUE(v2 == string("abc") + FILE_SEP + "def" + FILE_SEP + "ddd"); + + string v3 = TC_File::joinPaths("abc/", string("def/"), string("ddd")); + + ASSERT_TRUE(v3 == string("abc") + FILE_SEP + "def" + FILE_SEP + "ddd"); + + +} diff --git a/unit-test/util/test_tc_mysql.cpp b/unit-test/util/test_tc_mysql.cpp new file mode 100755 index 00000000..4e1abfc0 --- /dev/null +++ b/unit-test/util/test_tc_mysql.cpp @@ -0,0 +1,64 @@ +#include "util/tc_common.h" +#ifdef TARS_MYSQL +#include "util/tc_mysql.h" +#endif +#include "gtest/gtest.h" + +#include +#include + +using namespace std; +using namespace tars; + +class UtilMysqlTest : public testing::Test +{ +public: + //添加日志 + static void SetUpTestCase() + { + } + static void TearDownTestCase() + { + } + virtual void SetUp() //TEST跑之前会执行SetUp + { + } + virtual void TearDown() //TEST跑完之后会执行TearDown + { + } +}; + +#ifdef TARS_MYSQL + +TEST_F(UtilMysqlTest, test80) +{ + try + { + TC_Mysql mysql; + + mysql.init("127.0.0.1", "root", "123456", "", "utf8", 3307, 0); + + mysql.queryRecord("select 1"); + } + catch(exception &ex) + { + cerr << ex.what() << endl; + } + + try + { + TC_Mysql mysql; + + mysql.init("127.0.0.1", "root", "tars@12345", "", "utf8", 3306, 0); + + mysql.queryRecord("select 1"); + + cout << "success" << endl; + } + catch(exception &ex) + { + cerr << ex.what() << endl; + } +} + +#endif \ No newline at end of file diff --git a/unit-test/util/test_tc_option.cpp b/unit-test/util/test_tc_option.cpp new file mode 100755 index 00000000..14da3189 --- /dev/null +++ b/unit-test/util/test_tc_option.cpp @@ -0,0 +1,98 @@ +#include "util/tc_option.h" +#include "util/tc_common.h" +#include +#include "gtest/gtest.h" + +#include +#include + +using namespace std; +using namespace tars; + +class UtilOptionTest : public testing::Test +{ +public: + //添加日志 + static void SetUpTestCase() + { + } + static void TearDownTestCase() + { + } + virtual void SetUp() //TEST跑之前会执行SetUp + { + } + virtual void TearDown() //TEST跑完之后会执行TearDown + { + } +}; + +std::vector parseString(const std::string& input) +{ + std::vector result; + std::string currentString; + + bool insideQuotes = false; + + for (char c : input) { + if (c == ' ' && !insideQuotes) { + if (!currentString.empty()) { + result.push_back(currentString); + currentString.clear(); + } + } else if (c == '"' && !insideQuotes) { + currentString += c; + insideQuotes = true; + } else if (c == '"' && insideQuotes) { + currentString += c; + insideQuotes = false; + result.push_back(currentString); + currentString.clear(); + } else { + currentString += c; + } + } + + if (!currentString.empty()) { + result.push_back(currentString); + } + + return result; +} + +TEST_F(UtilOptionTest, option) +{ + string command = "server update --config=test.conf --abc --ep=\"tcp -h 127.0.0.1 -p 2345\""; + auto v = parseString(command.c_str()); + + EXPECT_EQ(v.size(), 5); +} + +TEST_F(UtilOptionTest, option_test) +{ + string command = "server update --config=test.conf --abc"; + + { + TC_Option option; + option.decode(command.c_str()); + + EXPECT_EQ(option.getSingle().size(), 2); + EXPECT_EQ(option.getSingle()[0], "server"); + EXPECT_EQ(option.getSingle()[1], "update"); + EXPECT_EQ(option.getValue("config"), "test.conf"); + EXPECT_EQ(option.hasParam("abc"), true); + } + + { + command = "server update --config=test.conf --abc --ep=\"tcp -h 127.0.0.1 -p 2345\""; + TC_Option option; + option.decode(command.c_str()); + EXPECT_EQ(option.getSingle().size(), 2); + EXPECT_EQ(option.getSingle()[0], "server"); + EXPECT_EQ(option.getSingle()[1], "update"); + EXPECT_EQ(option.getValue("config"), "test.conf"); + EXPECT_EQ(option.hasParam("abc"), true); + EXPECT_EQ(option.getValue("ep"), "tcp -h 127.0.0.1 -p 2345"); + } + +} diff --git a/unit-test/util/test_tc_port.cpp b/unit-test/util/test_tc_port.cpp index cfe889ce..1c14ea97 100755 --- a/unit-test/util/test_tc_port.cpp +++ b/unit-test/util/test_tc_port.cpp @@ -2,7 +2,7 @@ #include "util/tc_common.h" #include #include "gtest/gtest.h" - +#include "util/tc_file.h" #include #include @@ -32,4 +32,124 @@ TEST_F(UtilPortTest, testExec) string err; string result = TC_Port::exec("ls '*.txt'", err); cout << result << endl; + + string out = TC_Port::exec(("file " + TC_File::getExePath()).c_str()); + + cout << out << endl; +} + +TEST_F(UtilPortTest, testGetPidMemUsed) +{ + int64_t used = TC_Port::getPidMemUsed(TC_Port::getpid()); + cout << "used:" << used << endl; + + ASSERT_TRUE(used > 0); +} + +TEST_F(UtilPortTest, testGetPidStartTime) +{ + int64_t t = TC_Port::getPidStartTime(TC_Port::getpid()); + cout << "testGetPidStartTime:" << t << endl; + + ASSERT_TRUE(t >= time(NULL)); +} + +TEST_F(UtilPortTest, testGetUPTime) +{ + time_t t = TC_Port::getUPTime(); + cout << "testGetUPTime:" << (time(NULL)-t)/60/60/24 << "day" << endl; + ASSERT_TRUE(t > 0); } + +TEST_F(UtilPortTest, testGetSystemMemInfo) +{ + int64_t totalSize = 0; + int64_t availableSize = 0; + float usedPercent = 0; + + bool flag = TC_Port::getSystemMemInfo(totalSize, availableSize, usedPercent); + + cout << "totalSize: " << totalSize << endl; + cout << "availableSize: " << availableSize << endl; + cout << "usedPercent: " << usedPercent << endl; + ASSERT_TRUE(flag); + ASSERT_TRUE(totalSize > 0); + ASSERT_TRUE(availableSize > 0); + ASSERT_TRUE(usedPercent > 0); +} + +TEST_F(UtilPortTest, testGetCPUProcessor) +{ + int n = TC_Port::getCPUProcessor(); + + cout << "cpu: " << n << endl; + + ASSERT_TRUE(n > 0); +} + +TEST_F(UtilPortTest, testGetDiskInfo) +{ + float usedPercent = 0; + int64_t availableSize = 0; + int64_t totalSize = 0; + +#if TARGET_PLATFORM_IOS || TARGET_PLATFORM_LINUX + TC_Port::getDiskInfo(totalSize, availableSize, usedPercent, "/"); +#else + TC_Port::getDiskInfo(totalSize, availableSize, usedPercent, "c:\\"); +#endif + + cout << "totalSize: " << totalSize << endl; + cout << "usedPercent: " << usedPercent << endl; + cout << "availableSize: " << availableSize << endl; + + ASSERT_TRUE(totalSize > 0); + ASSERT_TRUE(usedPercent > 0); + ASSERT_TRUE(availableSize > 0); +} + +TEST_F(UtilPortTest, testGetCpuLoad) +{ + cout << "cpu load:" << TC_Port::getCpuLoad(500) << endl; +} + +#if TARGET_PLATFORM_WINDOWS +#include + +TEST_F(UtilPortTest, testGetDisk) +{ + DWORD aDrive = GetLogicalDrives(); + + for (int i = 0; i < 26; i++) { + if (aDrive & (1 << i)) { + char drive[4]; + sprintf(drive, "%c:\\", 'A' + i); + std::cout << drive << std::endl; + } + } +} + +#endif + +TEST_F(UtilPortTest, testGetCommandline) +{ + vector cmdLine = TC_Port::getCommandLine(TC_Port::getpid()); + + cout << cmdLine.size() << endl; + + string cmdStr = TC_Common::tostr(cmdLine.begin(), cmdLine.end(), " "); + cout << cmdStr << endl; + ASSERT_TRUE(cmdStr.find("unit-test") != string::npos); +} + +TEST_F(UtilPortTest, testGetPidsByCmdline) +{ + vector pids = TC_Port::getPidsByCmdline("unit-test", false); + + cout << TC_Common::tostr(pids.begin(), pids.end(), ", ") << endl; + + int64_t pid = TC_Port::getpid(); + + ASSERT_TRUE(std::find(pids.begin(), pids.end(), pid) != pids.end()); +} + diff --git a/unit-test/util/test_tc_socket.cpp b/unit-test/util/test_tc_socket.cpp new file mode 100755 index 00000000..f4c155df --- /dev/null +++ b/unit-test/util/test_tc_socket.cpp @@ -0,0 +1,45 @@ +#include "util/tc_common.h" +#include "util/tc_socket.h" +#include "gtest/gtest.h" + +#include +#include + +using namespace std; +using namespace tars; + +class UtilSocketTest : public testing::Test +{ +public: + //添加日志 + static void SetUpTestCase() + { + } + static void TearDownTestCase() + { + } + virtual void SetUp() //TEST跑之前会执行SetUp + { + } + virtual void TearDown() //TEST跑完之后会执行TearDown + { + } +}; + +TEST_F(UtilSocketTest, testGetLocalHosts) +{ + vector v1 = TC_Socket::getLocalHosts(AF_INET); + + for(size_t i = 0; i < v1.size(); i++) + { + cout << v1[i] << endl; + } + + vector v2 = TC_Socket::getLocalHosts(AF_INET6); + + for(size_t i = 0; i < v2.size(); i++) + { + cout << v2[i] << endl; + } +} + diff --git a/util/include/util/tc_common.h b/util/include/util/tc_common.h index edd1e64c..b3f0d13b 100644 --- a/util/include/util/tc_common.h +++ b/util/include/util/tc_common.h @@ -1438,10 +1438,11 @@ bool TC_Common::equal(const unordered_map& mx , const unordered_map< } #if TARGET_PLATFORM_WINDOWS -#define __filename__(x) (strrchr(x, '\\') ? strrchr(x, '\\') + 1 : x) -#define FILE_FUNC_LINE "[" << __filename__(__FILE__) << "::" << __FUNCTION__ << "::" << __LINE__ << "]" +#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) +#define FILE_FUNC_LINE "[" << __FILENAME__ << "::" << __FUNCTION__ << "::" << __LINE__ << "]" #else -#define FILE_FUNC_LINE "[" << __FILE__ << "::" << __FUNCTION__ << "::" << __LINE__ << "]" +#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__) +#define FILE_FUNC_LINE "[" << __FILENAME__ << "::" << __FUNCTION__ << "::" << __LINE__ << "]" #endif } diff --git a/util/include/util/tc_epoll_server.h b/util/include/util/tc_epoll_server.h index 57feaf35..82ebced3 100755 --- a/util/include/util/tc_epoll_server.h +++ b/util/include/util/tc_epoll_server.h @@ -1609,18 +1609,6 @@ class TC_EpollServer : public TC_HandleBase, public detail::LogInterface * 是否手工监听 */ bool _manualListen = false; -// /** -// * 创建一个udp句柄, 用来通知事后listen -// */ -// TC_Socket _udpNotify; -// -// /** -// * 通知 -// */ -// TC_Epoller::EpollInfo *_notifyInfo = NULL; - - //连接关闭的回调函数 -// close_functor _closeFunc; /** * ssl ctx @@ -2203,11 +2191,17 @@ class TC_EpollServer : public TC_HandleBase, public detail::LogInterface } /** - * 绑定监听socket + * 绑定并设置adapter * @param ls */ int bind(BindAdapterPtr &lsPtr); + /** + * 设置adapter + * @param adapters + */ + void setAdapter(const vector &adapters); + /** * 初始化handle对象 */ diff --git a/util/include/util/tc_fcontext.h b/util/include/util/tc_fcontext.h index 3d4a5c8d..13eb8d0b 100644 --- a/util/include/util/tc_fcontext.h +++ b/util/include/util/tc_fcontext.h @@ -12,8 +12,8 @@ struct transfer_t { void * data; }; -extern "C" transfer_t jump_fcontext( fcontext_t const to, void * vp); -extern "C" fcontext_t make_fcontext( void * sp, std::size_t size, void (* fn)( transfer_t) ); +extern "C" transfer_t tars_jump_fcontext( fcontext_t const to, void * vp); +extern "C" fcontext_t tars_make_fcontext( void * sp, std::size_t size, void (* fn)( transfer_t) ); } diff --git a/util/include/util/tc_file.h b/util/include/util/tc_file.h index 40946be0..db051152 100644 --- a/util/include/util/tc_file.h +++ b/util/include/util/tc_file.h @@ -82,6 +82,13 @@ class TC_File */ static bool isAbsolute(const string &sFullFileName); + /** + * 如果是相对路径则转换为绝对路径 + * @param sFullFileName + * @return + */ + static string toAbsolute(const string &sFullFileName); + /** * @brief 判断给定路径的文件是否存在. * 如果文件是符号连接,则以符号连接判断而不是以符号连接指向的文件判断 @@ -303,8 +310,35 @@ class TC_File */ static bool startWindowsPanfu(const string & sPath); + /** + * 连接参数, 变成路径 + * @tparam T + * @tparam Args + * @param t + * @param args + * @return + */ + template + static std::string joinPaths(T t, Args... args) { + std::string str_t = string(t); + if (!str_t.empty() && str_t.back() != FILE_SEP[0]) + str_t += FILE_SEP; + return str_t + joinPaths(args...); +// return string(t) + FILE_SEP + joinPaths(args...); + } private: - static bool isPanfu(const string & sPath); + // Base case: single argument + template + static std::string joinPaths(T t) { + return t; + } + + /** + * 是否是windows的盘符 + * @param sPath + * @return + */ + static bool isPanfu(const string & sPath); }; } #endif // TC_FILE_H diff --git a/util/include/util/tc_logger.h b/util/include/util/tc_logger.h index daa8dbe7..583ff1f2 100644 --- a/util/include/util/tc_logger.h +++ b/util/include/util/tc_logger.h @@ -297,9 +297,9 @@ namespace tars * @brief 启动线程. * @brief Start Thread * - * @param iThreadNum线程数 + * @param iThreadNum线程数, 无效, 永远为1 */ - void start(size_t iThreadNum); + void start(int iThreadNum = 1); /** * @brief 注册logger对象. @@ -325,8 +325,16 @@ namespace tars */ void flush(); + /** + * 结束 + */ void terminate(); + /** + * 是否已经启动了 + * @return + */ + bool isStart(); protected: /** * @brief 写日志 diff --git a/util/include/util/tc_option.h b/util/include/util/tc_option.h index 92cb0cb2..c393b929 100644 --- a/util/include/util/tc_option.h +++ b/util/include/util/tc_option.h @@ -143,6 +143,12 @@ class TC_Option */ void parse(const string &s); + /** + * @brief 使用" \t"分割, 如果碰到"则不分割 + * @param input + * @return + */ + std::vector parseString(const std::string& input); protected: /** *存放标识和其对应参数的对应关系,例如:对于--name=value,存放name和value diff --git a/util/include/util/tc_port.h b/util/include/util/tc_port.h index eda7ff1c..d88d45d6 100755 --- a/util/include/util/tc_port.h +++ b/util/include/util/tc_port.h @@ -46,6 +46,9 @@ struct TC_Port_Exception : public TC_Exception ~TC_Port_Exception() throw() {}; }; +/** + * 跨平台相关函数封装 + */ class TC_Port { public: @@ -56,39 +59,132 @@ class TC_Port */ static const char* strnstr(const char* s1, const char* s2, int pos1); + /** + * 字符串比较 + * @param s1 + * @param s2 + * @return + */ static int strcmp(const char *s1, const char *s2); + /** + * 字符串比较 + * @param s1 + * @param s2 + * @param n + * @return + */ static int strncmp(const char *s1, const char *s2, size_t n); + /** + * 忽略大小写比较 + * @param s1 + * @param s2 + * @return + */ static int strcasecmp(const char *s1, const char *s2); + /** + * 忽略大小写比较 + * @param s1 + * @param s2 + * @param n + * @return + */ static int strncasecmp(const char *s1, const char *s2, size_t n); + /** + * 从clock得到当前(到时区的)时间 + * @param clock + * @param result + */ static void localtime_r(const time_t *clock, struct tm *result); + /** + * 从clock得到当前时间GMT(不考虑时区, 夏令时等) + * @param clock + * @param result + */ static void gmtime_r(const time_t *clock, struct tm *result); + /** + * 转换成时间戳(GMT时间) + * @param timeptr + * @return + */ static time_t timegm(struct tm *timeptr); + /** + * 当前时间 + * @param tv + * @return + */ static int gettimeofday(struct timeval &tv); + /** + * 改变文件属性 + * @param path + * @param mode + * @return + */ static int chmod(const char *path, mode_t mode); - static FILE * fopen(const char * path, const char * mode); - #if TARGET_PLATFORM_WINDOWS typedef struct _stat stat_t; #else typedef struct stat stat_t; #endif + + /** + * 查看文件属性 + * @param path + * @param buf + * @return + */ static int lstat(const char * path, stat_t * buf); + /** + * 创建目录(可以使用TC_File下的函数makeDir/makeDirRecursive) + * @param path + * @return + */ static int mkdir(const char *path); + /** + * 删除路径 可以使用TC_File::removeFile + * @param path + * @return + */ static int rmdir(const char *path); + /** + * 打开一个文件 + * @param path + * @param mode + * @return + */ + static FILE * fopen(const char * path, const char * mode); + + /** + * src重定向到file + * @param src + * @param mode + * @param dst + * @return + */ + static FILE *freopen(const char * dst, const char * mode, FILE * src); + + /** + * 关闭网络句柄 + * @param fd + * @return + */ static int closeSocket(int fd); + /** + * 获取进程pid + * @return + */ static int64_t getpid(); /** @@ -105,11 +201,23 @@ class TC_Port */ static void setEnv(const std::string &name, const std::string &value); + /** + * 获取当前进程的目录 + * @return + */ + static string getCwd(); + + /** + * kill某个pid的进程 + * @param pid + */ + static void kill(int64_t pid); + /** * 运行一个脚本 * @param cmd * @param err - * @return 程序的标准输出(最大2k的输出长度) + * @return 程序的标准输出 */ static std::string exec(const char* cmd); @@ -117,21 +225,43 @@ class TC_Port * 运行一个脚本(程序+命令行) * @param cmd * @param err - * @return: 程序的标准输出(最大2k的输出长度) + * @return: 程序的标准输出 */ static std::string exec(const char* cmd, std::string &err); /** * fork子进程并运行程序 * @param sExe: 可执行程序路径 - * @param sPwdPath: 程序运行的当前路径 - * @param sRollLogPath: 滚动日志路径(stdout会重定向到滚动日志), 为空则不重定向 - * @param vOptions: 参数 + * @param sPwdPath: 设置程序运行的当前路径(chdir) + * @param sRollLogPath: 重定向输出路径(stdout/stderr会重定向到该日志文件), 为空则不重定向 + * @param vArgs: 参数 * @return 子进程id: ==0: 子进程中, >0: 父进程中(子进程pid), 其他抛出异常 TC_Port_Exception */ - static int64_t forkExec(const string& sExe, const string& sPwdPath, const string& sRollLogPath, const vector& vOptions); + static int64_t forkExec(const string& sExe, const string& sPwdPath, const string& sRollLogPath, const vector& vArgs); + +#if TARGET_PLATFORM_IOS || TARGET_PLATFORM_LINUX + /** + * 关闭所有当前进程的文件句柄(除了stdin/stdout/stderr) + */ + static void closeAllFileDescriptors(); +#endif - /** + /** + * 返回完整命令行参数, 如果pid不存在, 则返回为空 + * @param pid + * @return, 命令行参数, argv[0], argv[1] .... + */ + static std::vector getCommandLine(int64_t pid); + + /** + * 根据程序执行的命令行, 获取对应的进程pid + * @param cmdLine: 程序的启动完整命令行 + * @param accurateMatch: 匹配方式, true: 精确匹配, false: 模糊匹配(启动命令行能find到cmdLine) + * @return + */ + static vector getPidsByCmdline(const string &cmdLine, bool accurateMatch = false); + + /** * 注册ctrl+c回调事件(SIGINT/CTRL_C_EVENT) * @param callback * @return size_t, 注册事件的id, 取消注册时需要 @@ -158,39 +288,48 @@ class TC_Port */ static void unregisterTerm(size_t id); + /** + * 获取cpu负载 + * @param queryTime, windows下有效, 会阻塞的时间, 毫秒 + * + * @return, 如果失败, 返回-1, 否在返回cpu负载的值 + */ + static double getCpuLoad(uint32_t queryTime = 500); + /** - * 获取指定进程占用物理内存大小, 返回内存大小,默认单位(字节, 还支持K, M, G) (目前linux下才有效) + * 获取指定进程占用物理内存大小, 返回内存大小(K, M, G) * @param pid: 目标进程id + * @param unit: 指定单位 * return -1 表示获取失败 * */ static int64_t getPidMemUsed(int64_t pid, const char unit = 'M'); /** - * 获取进程启动时间(目前linux下才有效) + * 获取进程启动时间(秒) * @param pid * @return */ static time_t getPidStartTime(int64_t pid); /** - * 服务器启动时间(目前linux下才有效) + * 服务器启动的绝对时间(秒) * @return */ static time_t getUPTime(); /** - * 获取系统内存信息(目前linux下才有效) + * 获取系统内存信息 * @param totalSize, 总内存大小 * @param availableSize , 剩余可用内存大小 * @param usedPercent , 已使用内存百分比 - * @param unit, 内存单位 + * @param unit, 内存单位(B, K, G, M) * @return */ static bool getSystemMemInfo(int64_t &totalSize, int64_t &availableSize, float &usedPercent, const char unit = 'M'); /** - * 获取系统逻辑CPU核数(目前linux下才有效) + * 获取系统逻辑CPU核数 * @return -1 表示获取失败 */ static int getCPUProcessor(); @@ -198,11 +337,11 @@ class TC_Port /** * 获取磁盘信息 * @param usedPercent 磁盘使用百分比 - * @param availableSize 剩余磁盘空间(单位M) + * @param availableSize 剩余磁盘空间(字节数) * @param path, 为该路径所在目标磁盘 */ - static bool getDiskInfo(float& usedPercent, int64_t& availableSize, const string& path = "/"); + static bool getDiskInfo(int64_t &totalSize, int64_t& availableSize, float& usedPercent, const string& path); protected: diff --git a/util/include/util/tc_socket.h b/util/include/util/tc_socket.h index 13ec6adf..7e91b5a2 100644 --- a/util/include/util/tc_socket.h +++ b/util/include/util/tc_socket.h @@ -107,7 +107,7 @@ class TC_Socket * * @param fd socket句柄 * @param bOwner 是否拥有socket - * @param iDomain sokect协议族,缺省为AF_INET,代表TCP/IP协议族 + * @param iDomain socket协议族,缺省为AF_INET,代表TCP/IP协议族 */ void init(int fd, bool bOwner, int iDomain = AF_INET); @@ -498,11 +498,12 @@ class TC_Socket /** * @brief 获取本地所有ip. - * + * @param domain, AF_INET: ipv4, AF_INET6: ipv6 + * @param withLoopIp: 是否获取127.0.0.1 or ::1 地址 * @throws TC_Socket_Exception * @return 本地所有ip */ - static vector getLocalHosts(int domain = AF_INET); + static vector getLocalHosts(int domain = AF_INET, bool withLoopIp = true); /** * @brief 生成管道,抛出异常时会关闭fd. @@ -586,12 +587,12 @@ class TC_Socket */ static bool isInProgress(); - /** - * @brief 关闭句柄 - * - * @return - */ - static void closeSocketNoThrow(int); +// /** +// * @brief 关闭句柄 +// * +// * @return +// */ +// static void closeSocketNoThrow(int); #if 0 /** diff --git a/util/include/util/tc_uuid_generator.h b/util/include/util/tc_uuid_generator.h index a72655f5..7d7449ce 100644 --- a/util/include/util/tc_uuid_generator.h +++ b/util/include/util/tc_uuid_generator.h @@ -109,11 +109,11 @@ class TC_UUIDGenerator : public TC_Singleton string getLocalIP() { - vector vs = TC_Socket::getLocalHosts(); + vector vs = TC_Socket::getLocalHosts(AF_INET, false); for (size_t i = 0; i < vs.size(); i++) { - if (vs[i] != "127.0.0.1" && (!TC_Socket::addressIsIPv6(vs[i]))) + if (!TC_Socket::addressIsIPv6(vs[i])) { return vs[i]; } diff --git a/util/src/asm/jump_arm64_aapcs_elf_gas.S b/util/src/asm/jump_arm64_aapcs_elf_gas.S index cefd1830..ece57b8f 100644 --- a/util/src/asm/jump_arm64_aapcs_elf_gas.S +++ b/util/src/asm/jump_arm64_aapcs_elf_gas.S @@ -54,9 +54,9 @@ .file "jump_arm64_aapcs_elf_gas.S" .text .align 2 -.global jump_fcontext -.type jump_fcontext, %function -jump_fcontext: +.global tars_jump_fcontext +.type tars_jump_fcontext, %function +tars_jump_fcontext: # prepare stack for GP + FPU sub sp, sp, #0xb0 @@ -109,6 +109,6 @@ jump_fcontext: add sp, sp, #0xb0 ret x4 -.size jump_fcontext,.-jump_fcontext +.size tars_jump_fcontext,.-tars_jump_fcontext # Mark that we don't need executable stack. .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/jump_arm64_aapcs_macho_gas.S b/util/src/asm/jump_arm64_aapcs_macho_gas.S index 31738f74..a5a3a1e5 100644 --- a/util/src/asm/jump_arm64_aapcs_macho_gas.S +++ b/util/src/asm/jump_arm64_aapcs_macho_gas.S @@ -52,9 +52,9 @@ *******************************************************/ .text -.globl _jump_fcontext +.globl _tars_jump_fcontext .balign 16 -_jump_fcontext: +_tars_jump_fcontext: ; prepare stack for GP + FPU sub sp, sp, #0xb0 diff --git a/util/src/asm/jump_arm_aapcs_elf_gas.S b/util/src/asm/jump_arm_aapcs_elf_gas.S index 86efe9d8..ac72d33a 100644 --- a/util/src/asm/jump_arm_aapcs_elf_gas.S +++ b/util/src/asm/jump_arm_aapcs_elf_gas.S @@ -40,11 +40,11 @@ .file "jump_arm_aapcs_elf_gas.S" .text -.globl jump_fcontext +.globl tars_jump_fcontext .align 2 -.type jump_fcontext,%function +.type tars_jump_fcontext,%function .syntax unified -jump_fcontext: +tars_jump_fcontext: @ save LR as PC push {lr} @ save hidden,V1-V8,LR @@ -82,7 +82,7 @@ jump_fcontext: @ restore PC pop {pc} -.size jump_fcontext,.-jump_fcontext +.size tars_jump_fcontext,.-tars_jump_fcontext @ Mark that we don't need executable stack. .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/jump_arm_aapcs_macho_gas.S b/util/src/asm/jump_arm_aapcs_macho_gas.S index 8edd0d7d..09a6cc0e 100644 --- a/util/src/asm/jump_arm_aapcs_macho_gas.S +++ b/util/src/asm/jump_arm_aapcs_macho_gas.S @@ -39,9 +39,9 @@ *******************************************************/ .text -.globl _jump_fcontext +.globl _tars_jump_fcontext .align 2 -_jump_fcontext: +_tars_jump_fcontext: @ save LR as PC push {lr} @ save hidden,V1-V8,LR diff --git a/util/src/asm/jump_arm_aapcs_pe_armasm.asm b/util/src/asm/jump_arm_aapcs_pe_armasm.asm index bca923c6..4ec4492b 100644 --- a/util/src/asm/jump_arm_aapcs_pe_armasm.asm +++ b/util/src/asm/jump_arm_aapcs_pe_armasm.asm @@ -26,9 +26,9 @@ AREA |.text|, CODE ALIGN 4 - EXPORT jump_fcontext + EXPORT tars_jump_fcontext -jump_fcontext PROC +tars_jump_fcontext PROC ; save LR as PC push {lr} ; save hidden,V1-V8,LR diff --git a/util/src/asm/jump_i386_ms_pe_gas.asm b/util/src/asm/jump_i386_ms_pe_gas.asm index 6eb45326..900a78b8 100644 --- a/util/src/asm/jump_i386_ms_pe_gas.asm +++ b/util/src/asm/jump_i386_ms_pe_gas.asm @@ -32,9 +32,9 @@ .def @feat.00; .scl 3; .type 0; .endef .set @feat.00, 1 -.globl _jump_fcontext -.def _jump_fcontext; .scl 2; .type 32; .endef -_jump_fcontext: +.globl _tars_jump_fcontext +.def _tars_jump_fcontext; .scl 2; .type 32; .endef +_tars_jump_fcontext: /* prepare stack */ leal -0x2c(%esp), %esp @@ -71,7 +71,7 @@ _jump_fcontext: /* store ESP (pointing to context-data) in EAX */ movl %esp, %eax - /* firstarg of jump_fcontext() == fcontext to jump to */ + /* firstarg of tars_jump_fcontext() == fcontext to jump to */ movl 0x30(%esp), %ecx /* restore ESP (pointing to context-data) from ECX */ @@ -120,4 +120,4 @@ _jump_fcontext: jmp *%ecx .section .drectve -.ascii " -export:\"jump_fcontext\"" +.ascii " -export:\"tars_jump_fcontext\"" diff --git a/util/src/asm/jump_i386_ms_pe_masm.asm b/util/src/asm/jump_i386_ms_pe_masm.asm index 451d4835..681f98fb 100644 --- a/util/src/asm/jump_i386_ms_pe_masm.asm +++ b/util/src/asm/jump_i386_ms_pe_masm.asm @@ -24,7 +24,7 @@ .model flat, c .code -jump_fcontext PROC EXPORT +tars_jump_fcontext PROC EXPORT ; prepare stack lea esp, [esp-02ch] @@ -63,7 +63,7 @@ ENDIF ; store ESP (pointing to context-data) in EAX mov eax, esp - ; firstarg of jump_fcontext() == fcontext to jump to + ; firstarg of tars_jump_fcontext() == fcontext to jump to mov ecx, [esp+030h] ; restore ESP (pointing to context-data) from ECX @@ -112,5 +112,5 @@ ENDIF ; jump to context jmp ecx -jump_fcontext ENDP +tars_jump_fcontext ENDP END diff --git a/util/src/asm/jump_i386_sysv_elf_gas.S b/util/src/asm/jump_i386_sysv_elf_gas.S index b96d4b5c..c78b26cd 100644 --- a/util/src/asm/jump_i386_sysv_elf_gas.S +++ b/util/src/asm/jump_i386_sysv_elf_gas.S @@ -26,10 +26,10 @@ .file "jump_i386_sysv_elf_gas.S" .text -.globl jump_fcontext +.globl tars_jump_fcontext .align 2 -.type jump_fcontext,@function -jump_fcontext: +.type tars_jump_fcontext,@function +tars_jump_fcontext: leal -0x18(%esp), %esp /* prepare stack */ #if !defined(BOOST_USE_TSX) @@ -45,10 +45,10 @@ jump_fcontext: /* store ESP (pointing to context-data) in ECX */ movl %esp, %ecx - /* first arg of jump_fcontext() == fcontext to jump to */ + /* first arg of tars_jump_fcontext() == fcontext to jump to */ movl 0x20(%esp), %eax - /* second arg of jump_fcontext() == data to be transferred */ + /* second arg of tars_jump_fcontext() == data to be transferred */ movl 0x24(%esp), %edx /* restore ESP (pointing to context-data) from EAX */ @@ -77,7 +77,7 @@ jump_fcontext: /* jump to context */ jmp *%ecx -.size jump_fcontext,.-jump_fcontext +.size tars_jump_fcontext,.-tars_jump_fcontext /* Mark that we don't need executable stack. */ .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/jump_i386_sysv_macho_gas.S b/util/src/asm/jump_i386_sysv_macho_gas.S index 8ab7c6f2..d93f169a 100644 --- a/util/src/asm/jump_i386_sysv_macho_gas.S +++ b/util/src/asm/jump_i386_sysv_macho_gas.S @@ -25,9 +25,9 @@ ****************************************************************************************/ .text -.globl _jump_fcontext +.globl _tars_jump_fcontext .align 2 -_jump_fcontext: +_tars_jump_fcontext: leal -0x18(%esp), %esp /* prepare stack */ #if !defined(BOOST_USE_TSX) @@ -43,10 +43,10 @@ _jump_fcontext: /* store ESP (pointing to context-data) in ECX */ movl %esp, %ecx - /* first arg of jump_fcontext() == fcontext to jump to */ + /* first arg of tars_jump_fcontext() == fcontext to jump to */ movl 0x1c(%esp), %eax - /* second arg of jump_fcontext() == data to be transferred */ + /* second arg of tars_jump_fcontext() == data to be transferred */ movl 0x20(%esp), %edx /* restore ESP (pointing to context-data) from EAX */ diff --git a/util/src/asm/jump_mips32_o32_elf_gas.S b/util/src/asm/jump_mips32_o32_elf_gas.S index f2b8034d..ffb523df 100644 --- a/util/src/asm/jump_mips32_o32_elf_gas.S +++ b/util/src/asm/jump_mips32_o32_elf_gas.S @@ -40,11 +40,11 @@ .file "jump_mips32_o32_elf_gas.S" .text -.globl jump_fcontext +.globl tars_jump_fcontext .align 2 -.type jump_fcontext,@function -.ent jump_fcontext -jump_fcontext: +.type tars_jump_fcontext,@function +.ent tars_jump_fcontext +tars_jump_fcontext: # reserve space on stack addiu $sp, $sp, -96 @@ -112,8 +112,8 @@ jump_fcontext: # jump to context jr $t9 -.end jump_fcontext -.size jump_fcontext, .-jump_fcontext +.end tars_jump_fcontext +.size tars_jump_fcontext, .-tars_jump_fcontext /* Mark that we don't need executable stack. */ .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/jump_ppc32_sysv_elf_gas.S b/util/src/asm/jump_ppc32_sysv_elf_gas.S index 48e09c93..89b886cb 100644 --- a/util/src/asm/jump_ppc32_sysv_elf_gas.S +++ b/util/src/asm/jump_ppc32_sysv_elf_gas.S @@ -52,12 +52,12 @@ .file "jump_ppc32_sysv_elf_gas.S" .text -.globl jump_fcontext +.globl tars_jump_fcontext .align 2 -.type jump_fcontext,@function -jump_fcontext: - # Linux: jump_fcontext( hidden transfer_t * R3, R4, R5) - # Other: transfer_t R3:R4 = jump_fcontext( R3, R4) +.type tars_jump_fcontext,@function +tars_jump_fcontext: + # Linux: tars_jump_fcontext( hidden transfer_t * R3, R4, R5) + # Other: transfer_t R3:R4 = tars_jump_fcontext( R3, R4) mflr %r0 # return address from LR mffs %f0 # FPSCR @@ -195,7 +195,7 @@ jump_fcontext: # jump to context bctr -.size jump_fcontext, .-jump_fcontext +.size tars_jump_fcontext, .-tars_jump_fcontext /* Mark that we don't need executable stack. */ .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/jump_ppc32_sysv_macho_gas.S b/util/src/asm/jump_ppc32_sysv_macho_gas.S index c555237a..7e74737f 100644 --- a/util/src/asm/jump_ppc32_sysv_macho_gas.S +++ b/util/src/asm/jump_ppc32_sysv_macho_gas.S @@ -74,9 +74,9 @@ *******************************************************/ .text -.globl _jump_fcontext +.globl _tars_jump_fcontext .align 2 -_jump_fcontext: +_tars_jump_fcontext: ; reserve space on stack subi r1, r1, 244 diff --git a/util/src/asm/jump_ppc32_sysv_xcoff_gas.S b/util/src/asm/jump_ppc32_sysv_xcoff_gas.S index 5a967726..92e73ba7 100644 --- a/util/src/asm/jump_ppc32_sysv_xcoff_gas.S +++ b/util/src/asm/jump_ppc32_sysv_xcoff_gas.S @@ -72,13 +72,13 @@ * ------------------------------------------------- * * * *******************************************************/ -.globl .jump_fcontext -.globl jump_fcontext[DS] +.globl .tars_jump_fcontext +.globl tars_jump_fcontext[DS] .align 2 -.csect jump_fcontext[DS] -jump_fcontext: - .long .jump_fcontext -.jump_fcontext: +.csect tars_jump_fcontext[DS] +tars_jump_fcontext: + .long .tars_jump_fcontext +.tars_jump_fcontext: # reserve space on stack subi r1, r1, 244 diff --git a/util/src/asm/jump_ppc64_sysv_elf_gas.S b/util/src/asm/jump_ppc64_sysv_elf_gas.S index 28907db3..43e21d3b 100644 --- a/util/src/asm/jump_ppc64_sysv_elf_gas.S +++ b/util/src/asm/jump_ppc64_sysv_elf_gas.S @@ -67,33 +67,33 @@ *******************************************************/ .file "jump_ppc64_sysv_elf_gas.S" -.globl jump_fcontext +.globl tars_jump_fcontext #if _CALL_ELF == 2 .text .align 2 -jump_fcontext: - addis %r2, %r12, .TOC.-jump_fcontext@ha - addi %r2, %r2, .TOC.-jump_fcontext@l - .localentry jump_fcontext, . - jump_fcontext +tars_jump_fcontext: + addis %r2, %r12, .TOC.-tars_jump_fcontext@ha + addi %r2, %r2, .TOC.-tars_jump_fcontext@l + .localentry tars_jump_fcontext, . - tars_jump_fcontext #else .section ".opd","aw" .align 3 -jump_fcontext: +tars_jump_fcontext: # ifdef _CALL_LINUX - .quad .L.jump_fcontext,.TOC.@tocbase,0 - .type jump_fcontext,@function + .quad .L.tars_jump_fcontext,.TOC.@tocbase,0 + .type tars_jump_fcontext,@function .text .align 2 -.L.jump_fcontext: +.L.tars_jump_fcontext: # else - .hidden .jump_fcontext - .globl .jump_fcontext - .quad .jump_fcontext,.TOC.@tocbase,0 - .size jump_fcontext,24 - .type .jump_fcontext,@function + .hidden .tars_jump_fcontext + .globl .tars_jump_fcontext + .quad .tars_jump_fcontext,.TOC.@tocbase,0 + .size tars_jump_fcontext,24 + .type .tars_jump_fcontext,@function .text .align 2 -.jump_fcontext: +.tars_jump_fcontext: # endif #endif # reserve space on stack @@ -189,7 +189,7 @@ jump_fcontext: # jump to context bctr - .size jump_fcontext, .-jump_fcontext + .size tars_jump_fcontext, .-tars_jump_fcontext #else # zero in r3 indicates first jump to context-function cmpdi %r3, 0 @@ -210,9 +210,9 @@ use_entry_arg: # jump to context bctr # ifdef _CALL_LINUX - .size .jump_fcontext, .-.L.jump_fcontext + .size .tars_jump_fcontext, .-.L.tars_jump_fcontext # else - .size .jump_fcontext, .-.jump_fcontext + .size .tars_jump_fcontext, .-.tars_jump_fcontext # endif #endif diff --git a/util/src/asm/jump_ppc64_sysv_macho_gas.S b/util/src/asm/jump_ppc64_sysv_macho_gas.S index 74fcb2ab..4f647d74 100644 --- a/util/src/asm/jump_ppc64_sysv_macho_gas.S +++ b/util/src/asm/jump_ppc64_sysv_macho_gas.S @@ -68,9 +68,9 @@ .text .align 2 -.globl _jump_fcontext +.globl _tars_jump_fcontext -_jump_fcontext: +_tars_jump_fcontext: ; reserve space on stack subi r1, r1, 184 diff --git a/util/src/asm/jump_ppc64_sysv_xcoff_gas.S b/util/src/asm/jump_ppc64_sysv_xcoff_gas.S index ff0e6eaa..3a6e895a 100644 --- a/util/src/asm/jump_ppc64_sysv_xcoff_gas.S +++ b/util/src/asm/jump_ppc64_sysv_xcoff_gas.S @@ -7,8 +7,8 @@ */ .align 2 -.globl .jump_fcontext -.jump_fcontext: +.globl .tars_jump_fcontext +.tars_jump_fcontext: # reserve space on stack subi 1, 1, 184 diff --git a/util/src/asm/jump_x86_64_ms_pe_gas.asm b/util/src/asm/jump_x86_64_ms_pe_gas.asm index ec4ecfe9..e01af1fa 100644 --- a/util/src/asm/jump_x86_64_ms_pe_gas.asm +++ b/util/src/asm/jump_x86_64_ms_pe_gas.asm @@ -89,10 +89,10 @@ .file "jump_x86_64_ms_pe_gas.asm" .text .p2align 4,,15 -.globl jump_fcontext -.def jump_fcontext; .scl 2; .type 32; .endef -.seh_proc jump_fcontext -jump_fcontext: +.globl tars_jump_fcontext +.def tars_jump_fcontext; .scl 2; .type 32; .endef +.seh_proc tars_jump_fcontext +tars_jump_fcontext: .seh_endprologue leaq -0x118(%rsp), %rsp /* prepare stack */ @@ -206,4 +206,4 @@ jump_fcontext: .seh_endproc .section .drectve -.ascii " -export:\"jump_fcontext\"" +.ascii " -export:\"tars_jump_fcontext\"" diff --git a/util/src/asm/jump_x86_64_ms_pe_masm.asm b/util/src/asm/jump_x86_64_ms_pe_masm.asm index 4d5a4b33..63df0046 100644 --- a/util/src/asm/jump_x86_64_ms_pe_masm.asm +++ b/util/src/asm/jump_x86_64_ms_pe_masm.asm @@ -84,7 +84,7 @@ .code -jump_fcontext PROC EXPORT FRAME +tars_jump_fcontext PROC EXPORT FRAME .endprolog ; prepare stack @@ -201,5 +201,5 @@ ENDIF ; indirect jump to context jmp r10 -jump_fcontext ENDP +tars_jump_fcontext ENDP END diff --git a/util/src/asm/jump_x86_64_sysv_elf_gas.S b/util/src/asm/jump_x86_64_sysv_elf_gas.S index 0c4a1a39..84cf2e55 100644 --- a/util/src/asm/jump_x86_64_sysv_elf_gas.S +++ b/util/src/asm/jump_x86_64_sysv_elf_gas.S @@ -26,10 +26,10 @@ .file "jump_x86_64_sysv_elf_gas.S" .text -.globl jump_fcontext -.type jump_fcontext,@function +.globl tars_jump_fcontext +.type tars_jump_fcontext,@function .align 16 -jump_fcontext: +tars_jump_fcontext: leaq -0x38(%rsp), %rsp /* prepare stack */ #if !defined(BOOST_USE_TSX) @@ -85,7 +85,7 @@ jump_fcontext: /* indirect jump to context */ jmp *%r8 -.size jump_fcontext,.-jump_fcontext +.size tars_jump_fcontext,.-tars_jump_fcontext /* Mark that we don't need executable stack. */ .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/jump_x86_64_sysv_macho_gas.S b/util/src/asm/jump_x86_64_sysv_macho_gas.S index afc3e5c1..b798ba10 100644 --- a/util/src/asm/jump_x86_64_sysv_macho_gas.S +++ b/util/src/asm/jump_x86_64_sysv_macho_gas.S @@ -25,9 +25,9 @@ ****************************************************************************************/ .text -.globl _jump_fcontext +.globl _tars_jump_fcontext .align 8 -_jump_fcontext: +_tars_jump_fcontext: leaq -0x38(%rsp), %rsp /* prepare stack */ #if !defined(BOOST_USE_TSX) diff --git a/util/src/asm/make_arm64_aapcs_elf_gas.S b/util/src/asm/make_arm64_aapcs_elf_gas.S index 66cfb2da..5de794ed 100644 --- a/util/src/asm/make_arm64_aapcs_elf_gas.S +++ b/util/src/asm/make_arm64_aapcs_elf_gas.S @@ -54,16 +54,16 @@ .file "make_arm64_aapcs_elf_gas.S" .text .align 2 -.global make_fcontext -.type make_fcontext, %function -make_fcontext: +.global tars_make_fcontext +.type tars_make_fcontext, %function +tars_make_fcontext: # shift address in x0 (allocated stack) to lower 16 byte boundary and x0, x0, ~0xF # reserve space for context-data on context-stack sub x0, x0, #0xb0 - # third arg of make_fcontext() == address of context-function + # third arg of tars_make_fcontext() == address of context-function # store address as a PC to jump in str x2, [x0, #0xa0] @@ -80,6 +80,6 @@ finish: # exit application bl _exit -.size make_fcontext,.-make_fcontext +.size tars_make_fcontext,.-tars_make_fcontext # Mark that we don't need executable stack. .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/make_arm64_aapcs_macho_gas.S b/util/src/asm/make_arm64_aapcs_macho_gas.S index b30b1e3e..20e77788 100644 --- a/util/src/asm/make_arm64_aapcs_macho_gas.S +++ b/util/src/asm/make_arm64_aapcs_macho_gas.S @@ -52,17 +52,17 @@ *******************************************************/ .text -.globl _make_fcontext +.globl _tars_make_fcontext .balign 16 -_make_fcontext: +_tars_make_fcontext: ; shift address in x0 (allocated stack) to lower 16 byte boundary and x0, x0, ~0xF ; reserve space for context-data on context-stack sub x0, x0, #0xb0 - ; third arg of make_fcontext() == address of context-function + ; third arg of tars_make_fcontext() == address of context-function ; store address as a PC to jump in str x2, [x0, #0xa0] diff --git a/util/src/asm/make_arm_aapcs_elf_gas.S b/util/src/asm/make_arm_aapcs_elf_gas.S index 98ae64b4..0804e828 100644 --- a/util/src/asm/make_arm_aapcs_elf_gas.S +++ b/util/src/asm/make_arm_aapcs_elf_gas.S @@ -40,18 +40,18 @@ .file "make_arm_aapcs_elf_gas.S" .text -.globl make_fcontext +.globl tars_make_fcontext .align 2 -.type make_fcontext,%function +.type tars_make_fcontext,%function .syntax unified -make_fcontext: +tars_make_fcontext: @ shift address in A1 to lower 16 byte boundary bic a1, a1, #15 @ reserve space for context-data on context-stack sub a1, a1, #124 - @ third arg of make_fcontext() == address of context-function + @ third arg of tars_make_fcontext() == address of context-function str a3, [a1, #104] @ compute address of returned transfer_t @@ -75,7 +75,7 @@ finish: mov a1, #0 @ exit application bl _exit@PLT -.size make_fcontext,.-make_fcontext +.size tars_make_fcontext,.-tars_make_fcontext @ Mark that we don't need executable stack. .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/make_arm_aapcs_macho_gas.S b/util/src/asm/make_arm_aapcs_macho_gas.S index c909ae9d..3e831eeb 100644 --- a/util/src/asm/make_arm_aapcs_macho_gas.S +++ b/util/src/asm/make_arm_aapcs_macho_gas.S @@ -39,16 +39,16 @@ *******************************************************/ .text -.globl _make_fcontext +.globl _tars_make_fcontext .align 2 -_make_fcontext: +_tars_make_fcontext: @ shift address in A1 to lower 16 byte boundary bic a1, a1, #15 @ reserve space for context-data on context-stack sub a1, a1, #124 - @ third arg of make_fcontext() == address of context-function + @ third arg of tars_make_fcontext() == address of context-function str a3, [a1, #108] @ compute address of returned transfer_t diff --git a/util/src/asm/make_arm_aapcs_pe_armasm.asm b/util/src/asm/make_arm_aapcs_pe_armasm.asm index 27cbfb08..07c27eda 100644 --- a/util/src/asm/make_arm_aapcs_pe_armasm.asm +++ b/util/src/asm/make_arm_aapcs_pe_armasm.asm @@ -27,11 +27,11 @@ AREA |.text|, CODE ALIGN 4 - EXPORT make_fcontext + EXPORT tars_make_fcontext IMPORT _exit -make_fcontext PROC - ; first arg of make_fcontext() == top of context-stack +tars_make_fcontext PROC + ; first arg of tars_make_fcontext() == top of context-stack ; save top of context-stack (base) A4 mov a4, a1 @@ -43,7 +43,7 @@ make_fcontext PROC ; save top address of context_stack as 'base' str a4, [a1, #0x8] - ; second arg of make_fcontext() == size of context-stack + ; second arg of tars_make_fcontext() == size of context-stack ; compute bottom address of context-stack (limit) sub a4, a4, a2 ; save bottom address of context-stack as 'limit' @@ -51,7 +51,7 @@ make_fcontext PROC ; save bottom address of context-stack as 'dealloction stack' str a4, [a1, #0x0] - ; third arg of make_fcontext() == address of context-function + ; third arg of tars_make_fcontext() == address of context-function str a3, [a1, #0x34] ; compute address of returned transfer_t diff --git a/util/src/asm/make_i386_ms_pe_gas.asm b/util/src/asm/make_i386_ms_pe_gas.asm index 608ddf3a..86b0ea11 100644 --- a/util/src/asm/make_i386_ms_pe_gas.asm +++ b/util/src/asm/make_i386_ms_pe_gas.asm @@ -32,10 +32,10 @@ .def @feat.00; .scl 3; .type 0; .endef .set @feat.00, 1 -.globl _make_fcontext -.def _make_fcontext; .scl 2; .type 32; .endef -_make_fcontext: - /* first arg of make_fcontext() == top of context-stack */ +.globl _tars_make_fcontext +.def _tars_make_fcontext; .scl 2; .type 32; .endef +_tars_make_fcontext: + /* first arg of tars_make_fcontext() == top of context-stack */ movl 0x04(%esp), %eax /* reserve space for first argument of context-function */ @@ -56,11 +56,11 @@ _make_fcontext: /* save x87 control-word */ fnstcw 0x4(%eax) - /* first arg of make_fcontext() == top of context-stack */ + /* first arg of tars_make_fcontext() == top of context-stack */ movl 0x4(%esp), %ecx /* save top address of context stack as 'base' */ movl %ecx, 0x14(%eax) - /* second arg of make_fcontext() == size of context-stack */ + /* second arg of tars_make_fcontext() == size of context-stack */ movl 0x8(%esp), %edx /* negate stack size for LEA instruction (== substraction) */ negl %edx @@ -74,7 +74,7 @@ _make_fcontext: xorl %ecx, %ecx movl %ecx, 0x8(%eax) - /* third arg of make_fcontext() == address of context-function */ + /* third arg of tars_make_fcontext() == address of context-function */ /* stored in EBX */ movl 0xc(%esp), %ecx movl %ecx, 0x24(%eax) @@ -82,7 +82,7 @@ _make_fcontext: /* compute abs address of label trampoline */ movl $trampoline, %ecx /* save address of trampoline as return-address for context-function */ - /* will be entered after calling jump_fcontext() first time */ + /* will be entered after calling tars_jump_fcontext() first time */ movl %ecx, 0x2c(%eax) /* compute abs address of label finish */ @@ -150,4 +150,4 @@ finish: .def __exit; .scl 2; .type 32; .endef /* standard C library function */ .section .drectve -.ascii " -export:\"make_fcontext\"" +.ascii " -export:\"tars_make_fcontext\"" diff --git a/util/src/asm/make_i386_ms_pe_masm.asm b/util/src/asm/make_i386_ms_pe_masm.asm index 738fe0d9..9119d36d 100644 --- a/util/src/asm/make_i386_ms_pe_masm.asm +++ b/util/src/asm/make_i386_ms_pe_masm.asm @@ -26,8 +26,8 @@ _exit PROTO, value:SDWORD .code -make_fcontext PROC EXPORT - ; first arg of make_fcontext() == top of context-stack +tars_make_fcontext PROC EXPORT + ; first arg of tars_make_fcontext() == top of context-stack mov eax, [esp+04h] ; reserve space for first argument of context-function @@ -47,11 +47,11 @@ make_fcontext PROC EXPORT ; save x87 control-word fnstcw [eax+04h] - ; first arg of make_fcontext() == top of context-stack + ; first arg of tars_make_fcontext() == top of context-stack mov ecx, [esp+04h] ; save top address of context stack as 'base' mov [eax+014h], ecx - ; second arg of make_fcontext() == size of context-stack + ; second arg of tars_make_fcontext() == size of context-stack mov edx, [esp+08h] ; negate stack size for LEA instruction (== substraction) neg edx @@ -65,7 +65,7 @@ make_fcontext PROC EXPORT xor ecx, ecx mov [eax+08h], ecx - ; third arg of make_fcontext() == address of context-function + ; third arg of tars_make_fcontext() == address of context-function ; stored in EBX mov ecx, [esp+0ch] mov [eax+024h], ecx @@ -73,7 +73,7 @@ make_fcontext PROC EXPORT ; compute abs address of label trampoline mov ecx, trampoline ; save address of trampoline as return-address for context-function - ; will be entered after calling jump_fcontext() first time + ; will be entered after calling tars_jump_fcontext() first time mov [eax+02ch], ecx ; compute abs address of label finish @@ -136,5 +136,5 @@ finish: ; exit application call _exit hlt -make_fcontext ENDP +tars_make_fcontext ENDP END diff --git a/util/src/asm/make_i386_sysv_elf_gas.S b/util/src/asm/make_i386_sysv_elf_gas.S index b76de260..60502d66 100644 --- a/util/src/asm/make_i386_sysv_elf_gas.S +++ b/util/src/asm/make_i386_sysv_elf_gas.S @@ -26,11 +26,11 @@ .file "make_i386_sysv_elf_gas.S" .text -.globl make_fcontext +.globl tars_make_fcontext .align 2 -.type make_fcontext,@function -make_fcontext: - /* first arg of make_fcontext() == top of context-stack */ +.type tars_make_fcontext,@function +tars_make_fcontext: + /* first arg of tars_make_fcontext() == top of context-stack */ movl 0x4(%esp), %eax /* reserve space for first argument of context-function @@ -43,7 +43,7 @@ make_fcontext: /* reserve space for context-data on context-stack */ leal -0x28(%eax), %eax - /* third arg of make_fcontext() == address of context-function */ + /* third arg of tars_make_fcontext() == address of context-function */ /* stored in EBX */ movl 0xc(%esp), %ecx movl %ecx, 0x10(%eax) @@ -65,7 +65,7 @@ make_fcontext: /* compute abs address of label trampoline */ addl $trampoline-1b, %ecx /* save address of trampoline as return address */ - /* will be entered after calling jump_fcontext() first time */ + /* will be entered after calling tars_jump_fcontext() first time */ movl %ecx, 0x18(%eax) /* compute abs address of label finish */ @@ -101,7 +101,7 @@ finish: /* exit application */ call _exit@PLT hlt -.size make_fcontext,.-make_fcontext +.size tars_make_fcontext,.-tars_make_fcontext /* Mark that we don't need executable stack. */ .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/make_i386_sysv_macho_gas.S b/util/src/asm/make_i386_sysv_macho_gas.S index fdcdb7c8..f0d18220 100644 --- a/util/src/asm/make_i386_sysv_macho_gas.S +++ b/util/src/asm/make_i386_sysv_macho_gas.S @@ -25,10 +25,10 @@ ****************************************************************************************/ .text -.globl _make_fcontext +.globl _tars_make_fcontext .align 2 -_make_fcontext: - /* first arg of make_fcontext() == top of context-stack */ +_tars_make_fcontext: + /* first arg of tars_make_fcontext() == top of context-stack */ movl 0x4(%esp), %eax /* reserve space for first argument of context-function @@ -41,7 +41,7 @@ _make_fcontext: /* reserve space for context-data on context-stack */ leal -0x2c(%eax), %eax - /* third arg of make_fcontext() == address of context-function */ + /* third arg of tars_make_fcontext() == address of context-function */ /* stored in EBX */ movl 0xc(%esp), %ecx movl %ecx, 0x10(%eax) @@ -58,7 +58,7 @@ _make_fcontext: /* compute abs address of label trampoline */ addl $trampoline-1b, %ecx /* save address of trampoline as return address */ - /* will be entered after calling jump_fcontext() first time */ + /* will be entered after calling tars_jump_fcontext() first time */ movl %ecx, 0x18(%eax) /* compute abs address of label finish */ diff --git a/util/src/asm/make_mips32_o32_elf_gas.S b/util/src/asm/make_mips32_o32_elf_gas.S index 4e11e3d0..9c4eaf92 100644 --- a/util/src/asm/make_mips32_o32_elf_gas.S +++ b/util/src/asm/make_mips32_o32_elf_gas.S @@ -40,11 +40,11 @@ .file "make_mips32_o32_elf_gas.S" .text -.globl make_fcontext +.globl tars_make_fcontext .align 2 -.type make_fcontext,@function -.ent make_fcontext -make_fcontext: +.type tars_make_fcontext,@function +.ent tars_make_fcontext +tars_make_fcontext: #ifdef __PIC__ .set noreorder .cpload $t9 @@ -63,7 +63,7 @@ make_fcontext: # - 4 bytes for alignment addiu $v0, $v0, -128 - # third arg of make_fcontext() == address of context-function + # third arg of tars_make_fcontext() == address of context-function sw $a2, 92($v0) # save global pointer in context-data sw $gp, 112($v0) @@ -90,8 +90,8 @@ finish: la $t9, _exit move $a0, $zero jr $t9 -.end make_fcontext -.size make_fcontext, .-make_fcontext +.end tars_make_fcontext +.size tars_make_fcontext, .-tars_make_fcontext /* Mark that we don't need executable stack. */ .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/make_ppc32_sysv_elf_gas.S b/util/src/asm/make_ppc32_sysv_elf_gas.S index 9616c4ca..e6a39a57 100644 --- a/util/src/asm/make_ppc32_sysv_elf_gas.S +++ b/util/src/asm/make_ppc32_sysv_elf_gas.S @@ -52,14 +52,14 @@ .file "make_ppc32_sysv_elf_gas.S" .text -.globl make_fcontext +.globl tars_make_fcontext .align 2 -.type make_fcontext,@function -make_fcontext: +.type tars_make_fcontext,@function +tars_make_fcontext: # save return address into R6 mflr %r6 - # first arg of make_fcontext() == top address of context-function + # first arg of tars_make_fcontext() == top address of context-function # shift address in R3 to lower 16 byte boundary clrrwi %r3, %r3, 4 @@ -67,7 +67,7 @@ make_fcontext: # and parameter area + 240 bytes of context-data (R1 % 16 == 0) subi %r3, %r3, 16 + 240 - # third arg of make_fcontext() == address of context-function + # third arg of tars_make_fcontext() == address of context-function #ifdef __linux__ # save context-function as PC stw %r5, 16(%r3) @@ -111,7 +111,7 @@ make_fcontext: #ifndef __linux__ trampoline: - # On systems other than Linux, jump_fcontext is returning the + # On systems other than Linux, tars_jump_fcontext is returning the # transfer_t in R3:R4, but we need to pass transfer_t * R3 to # our context-function. lwz %r0, 8(%r1) # address of context-function @@ -136,7 +136,7 @@ finish: # call _exit(0) with special addend 0x8000 for large model li %r3, 0 bl _exit + 0x8000@plt -.size make_fcontext, .-make_fcontext +.size tars_make_fcontext, .-tars_make_fcontext /* Provide the GOT pointer for secure PLT, large model. */ .section .got2,"aw" diff --git a/util/src/asm/make_ppc32_sysv_macho_gas.S b/util/src/asm/make_ppc32_sysv_macho_gas.S index 8f35eff9..b8401ecc 100644 --- a/util/src/asm/make_ppc32_sysv_macho_gas.S +++ b/util/src/asm/make_ppc32_sysv_macho_gas.S @@ -74,13 +74,13 @@ *******************************************************/ .text -.globl _make_fcontext +.globl _tars_make_fcontext .align 2 -_make_fcontext: +_tars_make_fcontext: # save return address into R6 mflr r6 - # first arg of make_fcontext() == top address of context-function + # first arg of tars_make_fcontext() == top address of context-function # shift address in R3 to lower 16 byte boundary clrrwi r3, r3, 4 @@ -88,7 +88,7 @@ _make_fcontext: # including 64 byte of linkage + parameter area (R1 16 == 0) subi r3, r3, 336 - # third arg of make_fcontext() == address of context-function + # third arg of tars_make_fcontext() == address of context-function stw r5, 240(r3) # set back-chain to zero diff --git a/util/src/asm/make_ppc32_sysv_xcoff_gas.S b/util/src/asm/make_ppc32_sysv_xcoff_gas.S index f2572580..4712ae29 100644 --- a/util/src/asm/make_ppc32_sysv_xcoff_gas.S +++ b/util/src/asm/make_ppc32_sysv_xcoff_gas.S @@ -72,18 +72,18 @@ * ------------------------------------------------- * * * *******************************************************/ - .globl make_fcontext[DS] - .globl .make_fcontext[PR] + .globl tars_make_fcontext[DS] + .globl .tars_make_fcontext[PR] .align 2 - .csect make_fcontext[DS] -make_fcontext: - .long .make_fcontext[PR] - .csect .make_fcontext[PR], 3 -#.make_fcontext: + .csect tars_make_fcontext[DS] +tars_make_fcontext: + .long .tars_make_fcontext[PR] + .csect .tars_make_fcontext[PR], 3 +#.tars_make_fcontext: # save return address into R6 mflr 6 - # first arg of make_fcontext() == top address of context-function + # first arg of tars_make_fcontext() == top address of context-function # shift address in R3 to lower 16 byte boundary clrrwi 3, 3, 4 @@ -91,7 +91,7 @@ make_fcontext: # including 64 byte of linkage + parameter area (R1 % 16 == 0) subi 3, 3, 336 - # third arg of make_fcontext() == address of context-function + # third arg of tars_make_fcontext() == address of context-function stw 5, 240(3) # set back-chain to zero diff --git a/util/src/asm/make_ppc64_sysv_elf_gas.S b/util/src/asm/make_ppc64_sysv_elf_gas.S index c4d7ee59..0ec35e84 100644 --- a/util/src/asm/make_ppc64_sysv_elf_gas.S +++ b/util/src/asm/make_ppc64_sysv_elf_gas.S @@ -67,39 +67,39 @@ *******************************************************/ .file "make_ppc64_sysv_elf_gas.S" -.globl make_fcontext +.globl tars_make_fcontext #if _CALL_ELF == 2 .text .align 2 -make_fcontext: - addis %r2, %r12, .TOC.-make_fcontext@ha - addi %r2, %r2, .TOC.-make_fcontext@l - .localentry make_fcontext, . - make_fcontext +tars_make_fcontext: + addis %r2, %r12, .TOC.-tars_make_fcontext@ha + addi %r2, %r2, .TOC.-tars_make_fcontext@l + .localentry tars_make_fcontext, . - tars_make_fcontext #else .section ".opd","aw" .align 3 -make_fcontext: +tars_make_fcontext: # ifdef _CALL_LINUX - .quad .L.make_fcontext,.TOC.@tocbase,0 - .type make_fcontext,@function + .quad .L.tars_make_fcontext,.TOC.@tocbase,0 + .type tars_make_fcontext,@function .text .align 2 -.L.make_fcontext: +.L.tars_make_fcontext: # else - .hidden .make_fcontext - .globl .make_fcontext - .quad .make_fcontext,.TOC.@tocbase,0 - .size make_fcontext,24 - .type .make_fcontext,@function + .hidden .tars_make_fcontext + .globl .tars_make_fcontext + .quad .tars_make_fcontext,.TOC.@tocbase,0 + .size tars_make_fcontext,24 + .type .tars_make_fcontext,@function .text .align 2 -.make_fcontext: +.tars_make_fcontext: # endif #endif # save return address into R6 mflr %r6 - # first arg of make_fcontext() == top address of context-stack + # first arg of tars_make_fcontext() == top address of context-stack # shift address in R3 to lower 16 byte boundary clrrdi %r3, %r3, 4 @@ -107,7 +107,7 @@ make_fcontext: # including 64 byte of linkage + parameter area (R1 % 16 == 0) subi %r3, %r3, 248 - # third arg of make_fcontext() == address of context-function + # third arg of tars_make_fcontext() == address of context-function # entry point (ELFv2) or descriptor (ELFv1) #if _CALL_ELF == 2 # save address of context-function entry point @@ -164,12 +164,12 @@ finish: bl _exit nop #if _CALL_ELF == 2 - .size make_fcontext, .-make_fcontext + .size tars_make_fcontext, .-tars_make_fcontext #else # ifdef _CALL_LINUX - .size .make_fcontext, .-.L.make_fcontext + .size .tars_make_fcontext, .-.L.tars_make_fcontext # else - .size .make_fcontext, .-.make_fcontext + .size .tars_make_fcontext, .-.tars_make_fcontext # endif #endif diff --git a/util/src/asm/make_ppc64_sysv_macho_gas.S b/util/src/asm/make_ppc64_sysv_macho_gas.S index 7b947bb6..cdcb48f9 100644 --- a/util/src/asm/make_ppc64_sysv_macho_gas.S +++ b/util/src/asm/make_ppc64_sysv_macho_gas.S @@ -66,12 +66,12 @@ * * .text -.globl _make_fcontext -_make_fcontext: +.globl _tars_make_fcontext +_tars_make_fcontext: ; save return address into R6 mflr r6 - ; first arg of make_fcontext() == top address of context-function + ; first arg of tars_make_fcontext() == top address of context-function ; shift address in R3 to lower 16 byte boundary clrrwi r3, r3, 4 @@ -79,7 +79,7 @@ _make_fcontext: ; including 64 byte of linkage + parameter area (R1 16 == 0) subi r3, r3, 248 - ; third arg of make_fcontext() == address of context-function + ; third arg of tars_make_fcontext() == address of context-function stw r5, 176(r3) ; set back-chain to zero diff --git a/util/src/asm/make_ppc64_sysv_xcoff_gas.S b/util/src/asm/make_ppc64_sysv_xcoff_gas.S index 60ad6b6b..164172fc 100644 --- a/util/src/asm/make_ppc64_sysv_xcoff_gas.S +++ b/util/src/asm/make_ppc64_sysv_xcoff_gas.S @@ -4,16 +4,16 @@ (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ - .globl make_fcontext[DS] - .globl .make_fcontext[PR] + .globl tars_make_fcontext[DS] + .globl .tars_make_fcontext[PR] .align 2 - .csect .make_fcontext[PR], 3 - .globl _make_fcontext -#._make_fcontext: + .csect .tars_make_fcontext[PR], 3 + .globl _tars_make_fcontext +#._tars_make_fcontext: # save return address into R6 mflr 6 - # first arg of make_fcontext() == top address of context-function + # first arg of tars_make_fcontext() == top address of context-function # shift address in R3 to lower 16 byte boundary clrrwi 3, 3, 4 @@ -21,7 +21,7 @@ # including 64 byte of linkage + parameter area (R1 % 16 == 0) subi 3, 3, 248 - # third arg of make_fcontext() == address of context-function + # third arg of tars_make_fcontext() == address of context-function stw 5, 176(3) # set back-chain to zero diff --git a/util/src/asm/make_x86_64_ms_pe_gas.asm b/util/src/asm/make_x86_64_ms_pe_gas.asm index 958a2a7b..4e8eef06 100644 --- a/util/src/asm/make_x86_64_ms_pe_gas.asm +++ b/util/src/asm/make_x86_64_ms_pe_gas.asm @@ -89,13 +89,13 @@ .file "make_x86_64_ms_pe_gas.asm" .text .p2align 4,,15 -.globl make_fcontext -.def make_fcontext; .scl 2; .type 32; .endef -.seh_proc make_fcontext -make_fcontext: +.globl tars_make_fcontext +.def tars_make_fcontext; .scl 2; .type 32; .endef +.seh_proc tars_make_fcontext +tars_make_fcontext: .seh_endprologue - /* first arg of make_fcontext() == top of context-stack */ + /* first arg of tars_make_fcontext() == top of context-stack */ movq %rcx, %rax /* shift address in RAX to lower 16 byte boundary */ @@ -106,13 +106,13 @@ make_fcontext: /* on context-function entry: (RSP -0x8) % 16 == 0 */ leaq -0x150(%rax), %rax - /* third arg of make_fcontext() == address of context-function */ + /* third arg of tars_make_fcontext() == address of context-function */ movq %r8, 0x100(%rax) - /* first arg of make_fcontext() == top of context-stack */ + /* first arg of tars_make_fcontext() == top of context-stack */ /* save top address of context stack as 'base' */ movq %rcx, 0xc8(%rax) - /* second arg of make_fcontext() == size of context-stack */ + /* second arg of tars_make_fcontext() == size of context-stack */ /* negate stack size for LEA instruction (== substraction) */ negq %rdx /* compute bottom address of context stack (limit) */ @@ -138,7 +138,7 @@ make_fcontext: /* compute abs address of label trampoline */ leaq trampoline(%rip), %rcx /* save address of finish as return-address for context-function */ - /* will be entered after jump_fcontext() first time */ + /* will be entered after tars_jump_fcontext() first time */ movq %rcx, 0x118(%rax) /* compute abs address of label finish */ @@ -160,7 +160,7 @@ finish: /* 32byte shadow-space for _exit() */ andq $-32, %rsp /* 32byte shadow-space for _exit() are */ - /* already reserved by make_fcontext() */ + /* already reserved by tars_make_fcontext() */ /* exit code is zero */ xorq %rcx, %rcx /* exit application */ @@ -171,4 +171,4 @@ finish: .def _exit; .scl 2; .type 32; .endef /* standard C library function */ .section .drectve -.ascii " -export:\"make_fcontext\"" +.ascii " -export:\"tars_make_fcontext\"" diff --git a/util/src/asm/make_x86_64_ms_pe_masm.asm b/util/src/asm/make_x86_64_ms_pe_masm.asm index cccba893..ed4ebf0c 100644 --- a/util/src/asm/make_x86_64_ms_pe_masm.asm +++ b/util/src/asm/make_x86_64_ms_pe_masm.asm @@ -87,11 +87,11 @@ EXTERN _exit:PROC .code ; generate function table entry in .pdata and unwind information in -make_fcontext PROC EXPORT FRAME +tars_make_fcontext PROC EXPORT FRAME ; .xdata for a function's structured exception handling unwind behavior .endprolog - ; first arg of make_fcontext() == top of context-stack + ; first arg of tars_make_fcontext() == top of context-stack mov rax, rcx ; shift address in RAX to lower 16 byte boundary @@ -102,14 +102,14 @@ make_fcontext PROC EXPORT FRAME ; on context-function entry: (RSP -0x8) % 16 == 0 sub rax, 0150h - ; third arg of make_fcontext() == address of context-function + ; third arg of tars_make_fcontext() == address of context-function ; stored in RBX mov [rax+0100h], r8 - ; first arg of make_fcontext() == top of context-stack + ; first arg of tars_make_fcontext() == top of context-stack ; save top address of context stack as 'base' mov [rax+0c8h], rcx - ; second arg of make_fcontext() == size of context-stack + ; second arg of tars_make_fcontext() == size of context-stack ; negate stack size for LEA instruction (== substraction) neg rdx ; compute bottom address of context stack (limit) @@ -135,7 +135,7 @@ make_fcontext PROC EXPORT FRAME ; compute abs address of label trampoline lea rcx, trampoline ; save address of trampoline as return-address for context-function - ; will be entered after calling jump_fcontext() first time + ; will be entered after calling tars_jump_fcontext() first time mov [rax+0118h], rcx ; compute abs address of label finish @@ -159,5 +159,5 @@ finish: ; exit application call _exit hlt -make_fcontext ENDP +tars_make_fcontext ENDP END diff --git a/util/src/asm/make_x86_64_sysv_elf_gas.S b/util/src/asm/make_x86_64_sysv_elf_gas.S index 0ef37569..dfa0f7c7 100644 --- a/util/src/asm/make_x86_64_sysv_elf_gas.S +++ b/util/src/asm/make_x86_64_sysv_elf_gas.S @@ -26,11 +26,11 @@ .file "make_x86_64_sysv_elf_gas.S" .text -.globl make_fcontext -.type make_fcontext,@function +.globl tars_make_fcontext +.type tars_make_fcontext,@function .align 16 -make_fcontext: - /* first arg of make_fcontext() == top of context-stack */ +tars_make_fcontext: + /* first arg of tars_make_fcontext() == top of context-stack */ movq %rdi, %rax /* shift address in RAX to lower 16 byte boundary */ @@ -40,7 +40,7 @@ make_fcontext: /* on context-function entry: (RSP -0x8) % 16 == 0 */ leaq -0x40(%rax), %rax - /* third arg of make_fcontext() == address of context-function */ + /* third arg of tars_make_fcontext() == address of context-function */ /* stored in RBX */ movq %rdx, 0x28(%rax) @@ -52,7 +52,7 @@ make_fcontext: /* compute abs address of label trampoline */ leaq trampoline(%rip), %rcx /* save address of trampoline as return-address for context-function */ - /* will be entered after calling jump_fcontext() first time */ + /* will be entered after calling tars_jump_fcontext() first time */ movq %rcx, 0x38(%rax) /* compute abs address of label finish */ @@ -76,7 +76,7 @@ finish: /* exit application */ call _exit@PLT hlt -.size make_fcontext,.-make_fcontext +.size tars_make_fcontext,.-tars_make_fcontext /* Mark that we don't need executable stack. */ .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/make_x86_64_sysv_macho_gas.S b/util/src/asm/make_x86_64_sysv_macho_gas.S index 5d6c5431..df946141 100644 --- a/util/src/asm/make_x86_64_sysv_macho_gas.S +++ b/util/src/asm/make_x86_64_sysv_macho_gas.S @@ -25,10 +25,10 @@ ****************************************************************************************/ .text -.globl _make_fcontext +.globl _tars_make_fcontext .align 8 -_make_fcontext: - /* first arg of make_fcontext() == top of context-stack */ +_tars_make_fcontext: + /* first arg of tars_make_fcontext() == top of context-stack */ movq %rdi, %rax /* shift address in RAX to lower 16 byte boundary */ @@ -38,7 +38,7 @@ _make_fcontext: /* on context-function entry: (RSP -0x8) % 16 == 0 */ leaq -0x40(%rax), %rax - /* third arg of make_fcontext() == address of context-function */ + /* third arg of tars_make_fcontext() == address of context-function */ /* stored in RBX */ movq %rdx, 0x28(%rax) @@ -50,7 +50,7 @@ _make_fcontext: /* compute abs address of label trampoline */ leaq trampoline(%rip), %rcx /* save address of trampoline as return-address for context-function */ - /* will be entered after calling jump_fcontext() first time */ + /* will be entered after calling tars_jump_fcontext() first time */ movq %rcx, 0x38(%rax) /* compute abs address of label finish */ diff --git a/util/src/asm/ontop_arm64_aapcs_elf_gas.S b/util/src/asm/ontop_arm64_aapcs_elf_gas.S index 665ca5a2..5f9e2666 100644 --- a/util/src/asm/ontop_arm64_aapcs_elf_gas.S +++ b/util/src/asm/ontop_arm64_aapcs_elf_gas.S @@ -54,9 +54,9 @@ .file "ontop_arm64_aapcs_elf_gas.S" .text .align 2 -.global ontop_fcontext -.type ontop_fcontext, %function -ontop_fcontext: +.global tars_ontop_fcontext +.type tars_ontop_fcontext, %function +tars_ontop_fcontext: # prepare stack for GP + FPU sub sp, sp, #0xb0 @@ -108,6 +108,6 @@ ontop_fcontext: # jump to ontop-function ret x2 -.size ontop_fcontext,.-ontop_fcontext +.size tars_ontop_fcontext,.-tars_ontop_fcontext # Mark that we don't need executable stack. .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/ontop_arm64_aapcs_macho_gas.S b/util/src/asm/ontop_arm64_aapcs_macho_gas.S index a387d06d..43cc0afe 100644 --- a/util/src/asm/ontop_arm64_aapcs_macho_gas.S +++ b/util/src/asm/ontop_arm64_aapcs_macho_gas.S @@ -52,9 +52,9 @@ *******************************************************/ .text -.global _ontop_fcontext +.global _tars_ontop_fcontext .balign 16 -_ontop_fcontext: +_tars_ontop_fcontext: ; prepare stack for GP + FPU sub sp, sp, #0xb0 diff --git a/util/src/asm/ontop_arm_aapcs_elf_gas.S b/util/src/asm/ontop_arm_aapcs_elf_gas.S index 59ad5ca9..4a3e7633 100644 --- a/util/src/asm/ontop_arm_aapcs_elf_gas.S +++ b/util/src/asm/ontop_arm_aapcs_elf_gas.S @@ -40,11 +40,11 @@ .file "ontop_arm_aapcs_elf_gas.S" .text -.globl ontop_fcontext +.globl tars_ontop_fcontext .align 2 -.type ontop_fcontext,%function +.type tars_ontop_fcontext,%function .syntax unified -ontop_fcontext: +tars_ontop_fcontext: @ save LR as PC push {lr} @ save hidden,V1-V8,LR @@ -87,7 +87,7 @@ ontop_fcontext: @ jump to ontop-function bx a4 -.size ontop_fcontext,.-ontop_fcontext +.size tars_ontop_fcontext,.-tars_ontop_fcontext @ Mark that we don't need executable stack. .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/ontop_arm_aapcs_macho_gas.S b/util/src/asm/ontop_arm_aapcs_macho_gas.S index 421fcb45..62187e8b 100644 --- a/util/src/asm/ontop_arm_aapcs_macho_gas.S +++ b/util/src/asm/ontop_arm_aapcs_macho_gas.S @@ -39,9 +39,9 @@ *******************************************************/ .text -.globl _ontop_fcontext +.globl _tars_ontop_fcontext .align 2 -_ontop_fcontext: +_tars_ontop_fcontext: @ save LR as PC push {lr} @ save hidden,V1-V8,LR diff --git a/util/src/asm/ontop_arm_aapcs_pe_armasm.asm b/util/src/asm/ontop_arm_aapcs_pe_armasm.asm index f360a8ff..069204b1 100644 --- a/util/src/asm/ontop_arm_aapcs_pe_armasm.asm +++ b/util/src/asm/ontop_arm_aapcs_pe_armasm.asm @@ -26,9 +26,9 @@ AREA |.text|, CODE ALIGN 4 - EXPORT ontop_fcontext + EXPORT tars_ontop_fcontext -ontop_fcontext PROC +tars_ontop_fcontext PROC ; save LR as PC push {lr} ; save hidden,V1-V8,LR diff --git a/util/src/asm/ontop_i386_ms_pe_gas.asm b/util/src/asm/ontop_i386_ms_pe_gas.asm index abe9002a..ae49d64a 100644 --- a/util/src/asm/ontop_i386_ms_pe_gas.asm +++ b/util/src/asm/ontop_i386_ms_pe_gas.asm @@ -32,9 +32,9 @@ .def @feat.00; .scl 3; .type 0; .endef .set @feat.00, 1 -.globl _ontop_fcontext -.def _ontop_fcontext; .scl 2; .type 32; .endef -_ontop_fcontext: +.globl _tars_ontop_fcontext +.def _tars_ontop_fcontext; .scl 2; .type 32; .endef +_tars_ontop_fcontext: /* prepare stack */ leal -0x2c(%esp), %esp @@ -71,19 +71,19 @@ _ontop_fcontext: /* store ESP (pointing to context-data) in ECX */ movl %esp, %ecx - /* first arg of ontop_fcontext() == fcontext to jump to */ + /* first arg of tars_ontop_fcontext() == fcontext to jump to */ movl 0x30(%esp), %eax /* pass parent fcontext_t */ movl %ecx, 0x30(%eax) - /* second arg of ontop_fcontext() == data to be transferred */ + /* second arg of tars_ontop_fcontext() == data to be transferred */ movl 0x34(%esp), %ecx /* pass data */ movl %ecx, 0x34(%eax) - /* third arg of ontop_fcontext() == ontop-function */ + /* third arg of tars_ontop_fcontext() == ontop-function */ movl 0x38(%esp), %ecx /* restore ESP (pointing to context-data) from EDX */ @@ -128,4 +128,4 @@ _ontop_fcontext: jmp *%ecx .section .drectve -.ascii " -export:\"ontop_fcontext\"" +.ascii " -export:\"tars_ontop_fcontext\"" diff --git a/util/src/asm/ontop_i386_ms_pe_masm.asm b/util/src/asm/ontop_i386_ms_pe_masm.asm index 895578f3..4283a232 100644 --- a/util/src/asm/ontop_i386_ms_pe_masm.asm +++ b/util/src/asm/ontop_i386_ms_pe_masm.asm @@ -24,7 +24,7 @@ .model flat, c .code -ontop_fcontext PROC EXPORT +tars_ontop_fcontext PROC EXPORT ; prepare stack lea esp, [esp-02ch] @@ -63,19 +63,19 @@ ENDIF ; store ESP (pointing to context-data) in ECX mov ecx, esp - ; first arg of ontop_fcontext() == fcontext to jump to + ; first arg of tars_ontop_fcontext() == fcontext to jump to mov eax, [esp+030h] ; pass parent fcontext_t mov [eax+030h], ecx - ; second arg of ontop_fcontext() == data to be transferred + ; second arg of tars_ontop_fcontext() == data to be transferred mov ecx, [esp+034h] ; pass data mov [eax+034h], ecx - ; third arg of ontop_fcontext() == ontop-function + ; third arg of tars_ontop_fcontext() == ontop-function mov ecx, [esp+038h] ; restore ESP (pointing to context-data) from EAX @@ -120,5 +120,5 @@ ENDIF ; jump to context jmp ecx -ontop_fcontext ENDP +tars_ontop_fcontext ENDP END diff --git a/util/src/asm/ontop_i386_sysv_elf_gas.S b/util/src/asm/ontop_i386_sysv_elf_gas.S index 40fe6c2a..80dd0218 100644 --- a/util/src/asm/ontop_i386_sysv_elf_gas.S +++ b/util/src/asm/ontop_i386_sysv_elf_gas.S @@ -26,10 +26,10 @@ .file "ontop_i386_sysv_elf_gas.S" .text -.globl ontop_fcontext +.globl tars_ontop_fcontext .align 2 -.type ontop_fcontext,@function -ontop_fcontext: +.type tars_ontop_fcontext,@function +tars_ontop_fcontext: leal -0x18(%esp), %esp /* prepare stack */ #if !defined(BOOST_USE_TSX) @@ -45,19 +45,19 @@ ontop_fcontext: /* store ESP (pointing to context-data) in ECX */ movl %esp, %ecx - /* first arg of ontop_fcontext() == fcontext to jump to */ + /* first arg of tars_ontop_fcontext() == fcontext to jump to */ movl 0x20(%esp), %eax /* pass parent fcontext_t */ movl %ecx, 0x20(%eax) - /* second arg of ontop_fcontext() == data to be transferred */ + /* second arg of tars_ontop_fcontext() == data to be transferred */ movl 0x24(%esp), %ecx /* pass data */ movl %ecx, 0x24(%eax) - /* third arg of ontop_fcontext() == ontop-function */ + /* third arg of tars_ontop_fcontext() == ontop-function */ movl 0x28(%esp), %ecx /* restore ESP (pointing to context-data) from EAX */ @@ -84,7 +84,7 @@ ontop_fcontext: /* jump to context */ jmp *%ecx -.size ontop_fcontext,.-ontop_fcontext +.size tars_ontop_fcontext,.-tars_ontop_fcontext /* Mark that we don't need executable stack. */ .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/ontop_i386_sysv_macho_gas.S b/util/src/asm/ontop_i386_sysv_macho_gas.S index 3a88372b..81c87894 100644 --- a/util/src/asm/ontop_i386_sysv_macho_gas.S +++ b/util/src/asm/ontop_i386_sysv_macho_gas.S @@ -25,9 +25,9 @@ ****************************************************************************************/ .text -.globl _ontop_fcontext +.globl _tars_ontop_fcontext .align 2 -_ontop_fcontext: +_tars_ontop_fcontext: leal -0x18(%esp), %esp /* prepare stack */ #if !defined(BOOST_USE_TSX) @@ -43,19 +43,19 @@ _ontop_fcontext: /* store ESP (pointing to context-data) in ECX */ movl %esp, %ecx - /* first arg of ontop_fcontext() == fcontext to jump to */ + /* first arg of tars_ontop_fcontext() == fcontext to jump to */ movl 0x1c(%esp), %eax /* pass parent fcontext_t */ movl %ecx, 0x1c(%eax) - /* second arg of ontop_fcontext() == data to be transferred */ + /* second arg of tars_ontop_fcontext() == data to be transferred */ movl 0x20(%esp), %ecx /* pass data */ movl %ecx, 0x20(%eax) - /* third arg of ontop_fcontext() == ontop-function */ + /* third arg of tars_ontop_fcontext() == ontop-function */ movl 0x24(%esp), %ecx /* restore ESP (pointing to context-data) from EAX */ diff --git a/util/src/asm/ontop_mips32_o32_elf_gas.S b/util/src/asm/ontop_mips32_o32_elf_gas.S index c69203c6..6bb124d4 100644 --- a/util/src/asm/ontop_mips32_o32_elf_gas.S +++ b/util/src/asm/ontop_mips32_o32_elf_gas.S @@ -40,11 +40,11 @@ .file "ontop_mips32_o32_elf_gas.S" .text -.globl ontop_fcontext +.globl tars_ontop_fcontext .align 2 -.type ontop_fcontext,@function -.ent ontop_fcontext -ontop_fcontext: +.type tars_ontop_fcontext,@function +.ent tars_ontop_fcontext +tars_ontop_fcontext: # reserve space on stack addiu $sp, $sp, -96 @@ -113,8 +113,8 @@ ontop_fcontext: # jump to context jr $t9 -.end ontop_fcontext -.size ontop_fcontext, .-ontop_fcontext +.end tars_ontop_fcontext +.size tars_ontop_fcontext, .-tars_ontop_fcontext /* Mark that we don't need executable stack. */ .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/ontop_ppc32_sysv_elf_gas.S b/util/src/asm/ontop_ppc32_sysv_elf_gas.S index 464d99d5..96939e1c 100644 --- a/util/src/asm/ontop_ppc32_sysv_elf_gas.S +++ b/util/src/asm/ontop_ppc32_sysv_elf_gas.S @@ -52,12 +52,12 @@ .file "ontop_ppc32_sysv_elf_gas.S" .text -.globl ontop_fcontext +.globl tars_ontop_fcontext .align 2 -.type ontop_fcontext,@function -ontop_fcontext: - # Linux: ontop_fcontext( hidden transfer_t * R3, R4, R5, R6) - # Other: transfer_t R3:R4 = jump_fcontext( R3, R4, R5) +.type tars_ontop_fcontext,@function +tars_ontop_fcontext: + # Linux: tars_ontop_fcontext( hidden transfer_t * R3, R4, R5, R6) + # Other: transfer_t R3:R4 = tars_jump_fcontext( R3, R4, R5) mflr %r0 # return address from LR mffs %f0 # FPSCR @@ -186,8 +186,8 @@ ontop_fcontext: # see tail_ppc32_sysv_elf_gas.cpp # Linux: fcontext_ontop_tail( hidden transfer_t * R3, R4, R5, R6, R7) # Other: transfer_t R3:R4 = fcontext_ontop_tail( R3, R4, R5, R6) - b ontop_fcontext_tail -.size ontop_fcontext, .-ontop_fcontext + b tars_ontop_fcontext_tail +.size tars_ontop_fcontext, .-tars_ontop_fcontext /* Mark that we don't need executable stack. */ .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/ontop_ppc32_sysv_macho_gas.S b/util/src/asm/ontop_ppc32_sysv_macho_gas.S index 1eb5f934..30aa8372 100644 --- a/util/src/asm/ontop_ppc32_sysv_macho_gas.S +++ b/util/src/asm/ontop_ppc32_sysv_macho_gas.S @@ -74,9 +74,9 @@ *******************************************************/ .text -.globl _ontop_fcontext +.globl _tars_ontop_fcontext .align 2 -_ontop_fcontext: +_tars_ontop_fcontext: # reserve space on stack subi r1, r1, 244 diff --git a/util/src/asm/ontop_ppc32_sysv_xcoff_gas.S b/util/src/asm/ontop_ppc32_sysv_xcoff_gas.S index a3c9fa23..a8ed5b4d 100644 --- a/util/src/asm/ontop_ppc32_sysv_xcoff_gas.S +++ b/util/src/asm/ontop_ppc32_sysv_xcoff_gas.S @@ -72,13 +72,13 @@ * ------------------------------------------------- * * * *******************************************************/ -.globl .ontop_fcontext -.globl ontop_fcontext[DS] +.globl .tars_ontop_fcontext +.globl tars_ontop_fcontext[DS] .align 2 -.csect ontop_fcontext[DS] -ontop_fcontext: - .long .ontop_fcontext -.ontop_fcontext: +.csect tars_ontop_fcontext[DS] +tars_ontop_fcontext: + .long .tars_ontop_fcontext +.tars_ontop_fcontext: # reserve space on stack subi r1, r1, 244 diff --git a/util/src/asm/ontop_ppc64_sysv_elf_gas.S b/util/src/asm/ontop_ppc64_sysv_elf_gas.S index cd97f456..9bbac289 100644 --- a/util/src/asm/ontop_ppc64_sysv_elf_gas.S +++ b/util/src/asm/ontop_ppc64_sysv_elf_gas.S @@ -67,33 +67,33 @@ *******************************************************/ .file "ontop_ppc64_sysv_elf_gas.S" -.globl ontop_fcontext +.globl tars_ontop_fcontext #if _CALL_ELF == 2 .text .align 2 -ontop_fcontext: - addis %r2, %r12, .TOC.-ontop_fcontext@ha - addi %r2, %r2, .TOC.-ontop_fcontext@l - .localentry ontop_fcontext, . - ontop_fcontext +tars_ontop_fcontext: + addis %r2, %r12, .TOC.-tars_ontop_fcontext@ha + addi %r2, %r2, .TOC.-tars_ontop_fcontext@l + .localentry tars_ontop_fcontext, . - tars_ontop_fcontext #else .section ".opd","aw" .align 3 -ontop_fcontext: +tars_ontop_fcontext: # ifdef _CALL_LINUX - .quad .L.ontop_fcontext,.TOC.@tocbase,0 - .type ontop_fcontext,@function + .quad .L.tars_ontop_fcontext,.TOC.@tocbase,0 + .type tars_ontop_fcontext,@function .text .align 2 -.L.ontop_fcontext: +.L.tars_ontop_fcontext: # else - .hidden .ontop_fcontext - .globl .ontop_fcontext - .quad .ontop_fcontext,.TOC.@tocbase,0 - .size ontop_fcontext,24 - .type .ontop_fcontext,@function + .hidden .tars_ontop_fcontext + .globl .tars_ontop_fcontext + .quad .tars_ontop_fcontext,.TOC.@tocbase,0 + .size tars_ontop_fcontext,24 + .type .tars_ontop_fcontext,@function .text .align 2 -.ontop_fcontext: +.tars_ontop_fcontext: # endif #endif # reserve space on stack @@ -209,7 +209,7 @@ return_to_ctx: bctr #if _CALL_ELF == 2 - .size ontop_fcontext, .-ontop_fcontext + .size tars_ontop_fcontext, .-tars_ontop_fcontext #else use_entry_arg: # compute return-value struct address @@ -233,9 +233,9 @@ use_entry_arg: b return_to_ctx # ifdef _CALL_LINUX - .size .ontop_fcontext, .-.L.ontop_fcontext + .size .tars_ontop_fcontext, .-.L.tars_ontop_fcontext # else - .size .ontop_fcontext, .-.ontop_fcontext + .size .tars_ontop_fcontext, .-.tars_ontop_fcontext # endif #endif diff --git a/util/src/asm/ontop_ppc64_sysv_macho_gas.S b/util/src/asm/ontop_ppc64_sysv_macho_gas.S index 5de8acd1..37e031c0 100644 --- a/util/src/asm/ontop_ppc64_sysv_macho_gas.S +++ b/util/src/asm/ontop_ppc64_sysv_macho_gas.S @@ -68,9 +68,9 @@ .text .align 2 -.globl _ontop_fcontext +.globl _tars_ontop_fcontext -_ontop_fcontext: +_tars_ontop_fcontext: ; reserve space on stack subi r1, r1, 184 diff --git a/util/src/asm/ontop_ppc64_sysv_xcoff_gas.S b/util/src/asm/ontop_ppc64_sysv_xcoff_gas.S index 93f8c234..d953dfcd 100644 --- a/util/src/asm/ontop_ppc64_sysv_xcoff_gas.S +++ b/util/src/asm/ontop_ppc64_sysv_xcoff_gas.S @@ -1,6 +1,6 @@ .align 2 -.globl .ontop_fcontext -.ontop_fcontext: +.globl .tars_ontop_fcontext +.tars_ontop_fcontext: # reserve space on stack subi 1, 1, 184 diff --git a/util/src/asm/ontop_x86_64_ms_pe_gas.asm b/util/src/asm/ontop_x86_64_ms_pe_gas.asm index 02e040c9..7de98117 100644 --- a/util/src/asm/ontop_x86_64_ms_pe_gas.asm +++ b/util/src/asm/ontop_x86_64_ms_pe_gas.asm @@ -89,10 +89,10 @@ .file "ontop_x86_64_ms_pe_gas.asm" .text .p2align 4,,15 -.globl ontop_fcontext -.def ontop_fcontext; .scl 2; .type 32; .endef -.seh_proc ontop_fcontext -ontop_fcontext: +.globl tars_ontop_fcontext +.def tars_ontop_fcontext; .scl 2; .type 32; .endef +.seh_proc tars_ontop_fcontext +tars_ontop_fcontext: .seh_endprologue leaq -0x118(%rsp), %rsp /* prepare stack */ @@ -208,4 +208,4 @@ ontop_fcontext: .seh_endproc .section .drectve -.ascii " -export:\"ontop_fcontext\"" +.ascii " -export:\"tars_ontop_fcontext\"" diff --git a/util/src/asm/ontop_x86_64_ms_pe_masm.asm b/util/src/asm/ontop_x86_64_ms_pe_masm.asm index 99dfedb9..c07f371c 100644 --- a/util/src/asm/ontop_x86_64_ms_pe_masm.asm +++ b/util/src/asm/ontop_x86_64_ms_pe_masm.asm @@ -84,7 +84,7 @@ .code -ontop_fcontext PROC EXPORT FRAME +tars_ontop_fcontext PROC EXPORT FRAME .endprolog ; prepare stack @@ -203,5 +203,5 @@ ENDIF ; indirect jump to context jmp r9 -ontop_fcontext ENDP +tars_ontop_fcontext ENDP END diff --git a/util/src/asm/ontop_x86_64_sysv_elf_gas.S b/util/src/asm/ontop_x86_64_sysv_elf_gas.S index 4cdba400..6209c45e 100644 --- a/util/src/asm/ontop_x86_64_sysv_elf_gas.S +++ b/util/src/asm/ontop_x86_64_sysv_elf_gas.S @@ -26,10 +26,10 @@ .file "ontop_x86_64_sysv_elf_gas.S" .text -.globl ontop_fcontext -.type ontop_fcontext,@function +.globl tars_ontop_fcontext +.type tars_ontop_fcontext,@function .align 16 -ontop_fcontext: +tars_ontop_fcontext: /* preserve ontop-function in R8 */ movq %rdx, %r8 @@ -88,7 +88,7 @@ ontop_fcontext: /* indirect jump to context */ jmp *%r8 -.size ontop_fcontext,.-ontop_fcontext +.size tars_ontop_fcontext,.-tars_ontop_fcontext /* Mark that we don't need executable stack. */ .section .note.GNU-stack,"",%progbits diff --git a/util/src/asm/ontop_x86_64_sysv_macho_gas.S b/util/src/asm/ontop_x86_64_sysv_macho_gas.S index 49755c69..e9e90728 100644 --- a/util/src/asm/ontop_x86_64_sysv_macho_gas.S +++ b/util/src/asm/ontop_x86_64_sysv_macho_gas.S @@ -25,9 +25,9 @@ ****************************************************************************************/ .text -.globl _ontop_fcontext +.globl _tars_ontop_fcontext .align 8 -_ontop_fcontext: +_tars_ontop_fcontext: /* preserve ontop-function in R8 */ movq %rdx, %r8 diff --git a/util/src/tc_coroutine.cpp b/util/src/tc_coroutine.cpp index 3da86e16..46a68832 100755 --- a/util/src/tc_coroutine.cpp +++ b/util/src/tc_coroutine.cpp @@ -245,9 +245,9 @@ void TC_CoroutineInfo::registerFunc(const std::function& callback) _init_func.args = this; - fcontext_t ctx = make_fcontext(_stack_ctx.sp, _stack_ctx.size, TC_CoroutineInfo::corotineEntry); + fcontext_t ctx = tars_make_fcontext(_stack_ctx.sp, _stack_ctx.size, TC_CoroutineInfo::corotineEntry); - transfer_t tf = jump_fcontext(ctx, this); + transfer_t tf = tars_jump_fcontext(ctx, this); //实际的ctx this->setCtx(tf.fctx); @@ -260,7 +260,7 @@ void TC_CoroutineInfo::corotineEntry(transfer_t tf) auto func = coro->_init_func.coroFunc; void* args = coro->_init_func.args; - transfer_t t = jump_fcontext(tf.fctx, NULL); + transfer_t t = tars_jump_fcontext(tf.fctx, NULL); //拿到自己的协程堆栈, 当前协程结束以后, 好跳转到main coro->_scheduler->setMainCtx(t.fctx); @@ -688,7 +688,7 @@ void TC_CoroutineScheduler::switchCoro(TC_CoroutineInfo *to) //跳转到to协程 _currentCoro = to; - transfer_t t = jump_fcontext(to->getCtx(), NULL); + transfer_t t = tars_jump_fcontext(to->getCtx(), NULL); //并保存协程堆栈 to->setCtx(t.fctx); diff --git a/util/src/tc_epoll_server.cpp b/util/src/tc_epoll_server.cpp index 75ac44c4..691b1e80 100644 --- a/util/src/tc_epoll_server.cpp +++ b/util/src/tc_epoll_server.cpp @@ -664,7 +664,7 @@ bool TC_EpollServer::Connection::handleInputImp(const shared_ptrerror(ex.what()); +// _logger->error(ex.what()); netThread->delConnection(this, true, EM_CLIENT_CLOSE); return false; } @@ -1398,9 +1398,6 @@ TC_EpollServer::BindAdapter::~BindAdapter() void TC_EpollServer::BindAdapter::bind() { - // try - // { - assert(!_s.isValid()); #if TARGET_PLATFORM_WINDOWS @@ -1452,13 +1449,6 @@ void TC_EpollServer::BindAdapter::bind() } } _s.setblock(false); - // } - // catch(exception &ex) - // { - // _s.close(); - // cerr << "bind:" << _ep.toString() << " error:" << ex.what() << endl; - // throw ex; - // } } void TC_EpollServer::BindAdapter::setNetThreads(const vector &netThreads) @@ -1908,17 +1898,23 @@ TC_EpollServer::TC_EpollServer(unsigned int iNetThreadNum) { #if TARGET_PLATFORM_WINDOWS WSADATA wsadata; -WSAStartup(MAKEWORD(2, 2), &wsadata); + WSAStartup(MAKEWORD(2, 2), &wsadata); #endif -// -// _epoller.create(10240); -// _epoller.setName("epollserver-epoller"); + + _epoller = new TC_Epoller(); + _epoller->create(10240); + _epoller->setName("epollserver-epoller"); + } TC_EpollServer::~TC_EpollServer() { terminate(); + delete _epoller; + + _epoller = NULL; + #if TARGET_PLATFORM_WINDOWS WSACleanup(); #endif @@ -2011,15 +2007,7 @@ bool TC_EpollServer::accept(int fd, int domain) return true; } - // else - // { - // //直到发生EAGAIN才不继续accept - // if (TC_Socket::isPending()) - // { - // return false; - // } - // } - // return true; + return false; } @@ -2105,9 +2093,7 @@ void TC_EpollServer::listenCallback(weak_ptr adapterPtr) void TC_EpollServer::waitForShutdown() { - _epoller = new TC_Epoller(); - _epoller->create(10240); - _epoller->setName("epollserver-epoller"); + _epoller->reset(); _readyThreadNum = 0; @@ -2122,7 +2108,7 @@ void TC_EpollServer::waitForShutdown() _epoller->postRepeated(5000, false, [&](){ _hf(this);}); } - for(auto it : _bindAdapters) + for(const auto& it : _bindAdapters) { if(it->getEndpoint().isTcp()) { @@ -2192,9 +2178,9 @@ void TC_EpollServer::waitForShutdown() bindAdapter->getHandles().clear(); } - delete _epoller; - - _epoller = NULL; +// delete _epoller; +// +// _epoller = NULL; std::unique_lock lock(_readyMutex); @@ -2205,11 +2191,15 @@ void TC_EpollServer::waitForShutdown() void TC_EpollServer::terminate() { - if(_epoller == NULL || _epoller->isTerminate()) + if(_epoller->isTerminate()) { return; } - +// if(_epoller == NULL || _epoller->isTerminate()) +// { +// return; +// } +// //先停止网络线程 _epoller->terminate(); @@ -2227,6 +2217,11 @@ void TC_EpollServer::setEmptyConnTimeout(int timeout) } } +void TC_EpollServer::setAdapter(const vector &adapters) +{ + _bindAdapters = adapters; +} + int TC_EpollServer::bind(BindAdapterPtr & lsPtr) { auto it = _listeners.begin(); @@ -2237,6 +2232,7 @@ int TC_EpollServer::bind(BindAdapterPtr & lsPtr) { throw TC_Exception("bind name '" + lsPtr->getName() + "' conflicts."); } + ++it; } @@ -2247,7 +2243,11 @@ int TC_EpollServer::bind(BindAdapterPtr & lsPtr) _listeners[lsPtr->getSocket().getfd()] = lsPtr; } - _bindAdapters.push_back(lsPtr); + //如果adapter没有添加过, 则添加 + if(!getBindAdapter(lsPtr->getName())) + { + _bindAdapters.push_back(lsPtr); + } return lsPtr->getSocket().getfd(); } diff --git a/util/src/tc_file.cpp b/util/src/tc_file.cpp index 96c72a10..a5e78586 100644 --- a/util/src/tc_file.cpp +++ b/util/src/tc_file.cpp @@ -60,6 +60,15 @@ bool TC_File::isAbsolute(const string &sFullFileName) #endif } +string TC_File::toAbsolute(const string &sFullFileName) +{ + if(!isAbsolute(sFullFileName)) + { + return simplifyDirectory(TC_Port::getCwd() + FILE_SEP + sFullFileName); + } + return sFullFileName; +} + bool TC_File::isFileExist(const string &sFullFileName, mode_t iFileType) { TC_Port::stat_t f_stat; @@ -146,21 +155,9 @@ string TC_File::getExePath() #elif TARGET_PLATFORM_IOS string TC_File::getExePath() { - int numberOfProcesses = proc_listpids(PROC_ALL_PIDS, 0, NULL, 0); - pid_t pids[numberOfProcesses]; - bzero(pids, sizeof(pids)); - proc_listpids(PROC_ALL_PIDS, 0, pids, sizeof(pids)); char pathBuffer[PROC_PIDPATHINFO_MAXSIZE]; bzero(pathBuffer, PROC_PIDPATHINFO_MAXSIZE); - for (int i = 0; i < numberOfProcesses; ++i) { - if (pids[i] == 0) { continue; } - - if(pids[i] == getpid()) - { - proc_pidpath(pids[i], pathBuffer, sizeof(pathBuffer)); - break; - } - } + proc_pidpath(getpid(), pathBuffer, sizeof(pathBuffer)); return pathBuffer; } @@ -687,6 +684,7 @@ void TC_File::copyFile(const string &sExistFile, const string &sNewFile,bool bRe { THROW_EXCEPTION_SYSCODE(TC_File_Exception, "[TC_File::copyFile] error: "+sExistFile); } + //强制覆盖 std::ofstream fout(sNewFile.c_str(), ios::binary); if(!fout ) { diff --git a/util/src/tc_gzip.cpp b/util/src/tc_gzip.cpp index 8f1a43e1..a77b090a 100644 --- a/util/src/tc_gzip.cpp +++ b/util/src/tc_gzip.cpp @@ -42,7 +42,7 @@ bool TC_GZip::compress(const char *src, size_t length, string& buffer) static char gz_simple_header[] = { '\037', '\213', '\010', '\000', '\000', '\000', '\000', '\000', '\002', '\377' }; size_t destLen = sizeof(gz_simple_header) + length * 2; - char *out = new char[destLen]; + char *out = new char[destLen + 1]; stream.next_out = (Bytef *)out; stream.avail_out = destLen; @@ -100,7 +100,7 @@ bool TC_GZip::compress(const char *src, size_t length, vector& buffer) static char gz_simple_header[] = { '\037', '\213', '\010', '\000', '\000', '\000', '\000', '\000', '\002', '\377' }; size_t destLen = sizeof(gz_simple_header) + length * 2; - char *out = new char[destLen]; + char *out = new char[destLen + 1]; stream.next_out = (Bytef *)out; stream.avail_out = destLen; diff --git a/util/src/tc_logger.cpp b/util/src/tc_logger.cpp index b7074935..e42327b2 100644 --- a/util/src/tc_logger.cpp +++ b/util/src/tc_logger.cpp @@ -121,7 +121,7 @@ TC_LoggerThreadGroup::~TC_LoggerThreadGroup() terminate(); } -void TC_LoggerThreadGroup::start(size_t iThreadNum) +void TC_LoggerThreadGroup::start(int iThreadNum) { if(!_thread) { @@ -129,6 +129,11 @@ void TC_LoggerThreadGroup::start(size_t iThreadNum) } } +bool TC_LoggerThreadGroup::isStart() +{ + return _thread.get() != nullptr; +} + void TC_LoggerThreadGroup::registerLogger(TC_LoggerRollPtr &l) { std::lock_guard lock(_mutex); @@ -159,6 +164,7 @@ void TC_LoggerThreadGroup::terminate() if (_thread) { _thread->join(); + _thread.reset(); } } diff --git a/util/src/tc_mysql.cpp b/util/src/tc_mysql.cpp index 986f9faa..ff88d59a 100644 --- a/util/src/tc_mysql.cpp +++ b/util/src/tc_mysql.cpp @@ -114,6 +114,9 @@ void TC_Mysql::connect() } } + unsigned int i = 1; + + mysql_options(_pstMql, MYSQL_OPT_SSL_MODE, &i); if (mysql_real_connect(_pstMql, _dbConf._host.c_str(), _dbConf._user.c_str(), _dbConf._password.c_str(), _dbConf._database.c_str(), _dbConf._port, NULL, _dbConf._flag) == NULL) { diff --git a/util/src/tc_option.cpp b/util/src/tc_option.cpp index 29bc5e70..820e235f 100644 --- a/util/src/tc_option.cpp +++ b/util/src/tc_option.cpp @@ -41,12 +41,45 @@ void TC_Option::decode(int argc, char *argv[]) } } } + +std::vector TC_Option::parseString(const std::string& input) +{ + std::vector result; + std::string currentString; + + bool insideQuotes = false; + + for (char c : input) { + if ((c == ' ' || c == '\t') && !insideQuotes) { + if (!currentString.empty()) { + result.push_back(currentString); + currentString.clear(); + } + } else if (c == '"' && !insideQuotes) { +// currentString += c; + insideQuotes = true; + } else if (c == '"' && insideQuotes) { +// currentString += c; + insideQuotes = false; + } else { + currentString += c; + } + } + + if (!currentString.empty()) { + result.push_back(currentString); + } + + return result; +} + void TC_Option::decode(const char *command) { _mParam.clear(); if(command == NULL) return; - vector v = TC_Common::sepstr(command, " \t"); +// vector v = TC_Common::sepstr(command, " \t"); + vector v = parseString(command); for(size_t i = 0; i < v.size(); i++) { diff --git a/util/src/tc_port.cpp b/util/src/tc_port.cpp index 43c899b7..604c9bca 100755 --- a/util/src/tc_port.cpp +++ b/util/src/tc_port.cpp @@ -35,12 +35,29 @@ #else #pragma comment(lib, "ws2_32.lib") -// #include +#pragma comment(lib, "pdh.lib") + +#include #include #include +#include +#include +#include +#include +#include +#include + #include "util/tc_strptime.h" #endif +#if TARGET_PLATFORM_IOS +#include +#include +#include +#include +#include +#endif + namespace tars { @@ -247,6 +264,34 @@ void TC_Port::setEnv(const string &name, const string &value) #endif } +string TC_Port::getCwd() +{ + char currentDirectory[FILENAME_MAX] = {0x00}; +#if TARGET_PLATFORM_WINDOWS + _getcwd(currentDirectory, sizeof(currentDirectory)); +#else + getcwd(currentDirectory, sizeof(currentDirectory)); +#endif + return currentDirectory; +} + +void TC_Port::kill(int64_t pid) +{ +#if TARGET_PLATFORM_WINDOWS + HANDLE hProcess = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid); + if (hProcess == NULL) + { + return; + } + + ::TerminateProcess(hProcess, 0); + + CloseHandle(hProcess); +#else + ::kill(static_cast(pid), SIGKILL); +#endif +} + string TC_Port::exec(const char *cmd) { string err; @@ -255,29 +300,435 @@ string TC_Port::exec(const char *cmd) std::string TC_Port::exec(const char* cmd, std::string &err) { - string fileData; + std::string result; #if TARGET_PLATFORM_WINDOWS FILE* fp = _popen(cmd, "r"); #else FILE* fp = popen(cmd, "r"); #endif - if(fp == NULL) { - err = "open '" + string(cmd) + "' error"; - return ""; - } - static size_t buf_len = 2 * 1024 * 1024; - char *buf = new char[buf_len]; - memset(buf, 0, buf_len); - fread(buf, sizeof(char), buf_len - 1, fp); + if(fp == NULL) { + err = "open '" + string(cmd) + "' error"; + return ""; + } + + char buffer[1024]; + while (!feof(fp)) { + if (fgets(buffer, 1024, fp) != NULL) + result.append(buffer); + } + #if TARGET_PLATFORM_WINDOWS _pclose(fp); #else pclose(fp); #endif - fileData = string(buf); - delete []buf; - return fileData; + return result; +} + +#if TARGET_PLATFORM_LINUX +void TC_Port::closeAllFileDescriptors() { + DIR *dir; + struct dirent *entry; + int fd; + + dir = opendir("/proc/self/fd"); + if (dir == NULL) { + perror("Cannot open /proc/self/fd"); + exit(EXIT_FAILURE); + } + + while ((entry = readdir(dir)) != NULL) { + fd = atoi(entry->d_name); + if (fd > STDERR_FILENO) { // Skip stdin, stdout, and stderr + close(fd); + } + } + + closedir(dir); +} + +#elif TARGET_PLATFORM_IOS + +void TC_Port::closeAllFileDescriptors() +{ + int max_fd; + int fd; + size_t len = sizeof(max_fd); + + // Get the maximum file descriptor number for the current process + if (sysctlbyname("kern.maxfilesperproc", &max_fd, &len, NULL, 0) < 0) + { + return; + } + + for (fd = STDERR_FILENO + 1; fd < max_fd; fd++) + { + close(fd); + } +} + +#endif + +#if TARGET_PLATFORM_LINUX +std::vector TC_Port::getCommandLine(int64_t pid) +{ + std::vector commandLineArgs; + + std::string procPath = "/proc/" + std::to_string(pid) + "/cmdline"; + std::ifstream cmdlineFile(procPath); + if (!cmdlineFile.is_open()) { + return {}; + } + + std::stringstream buffer; + buffer << cmdlineFile.rdbuf(); + std::string cmdline = buffer.str(); + + size_t pos = 0; + while (pos < cmdline.size()) { + std::string arg; + size_t nextPos = cmdline.find('\0', pos); + if (nextPos == std::string::npos) { + arg = cmdline.substr(pos); + pos = cmdline.size(); + } else { + arg = cmdline.substr(pos, nextPos - pos); + pos = nextPos + 1; + } + commandLineArgs.push_back(arg); + } + + return commandLineArgs; +} +#endif + +#if TARGET_PLATFORM_WINDOWS + +std::vector TC_Port::getCommandLine(int64_t pid) +{ + HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, static_cast(pid)); + if (hProcess == NULL) { + return {}; + } + + std::vector commandLineArgs; + + LPWSTR cmdLine = GetCommandLineW(); + + int argc; + LPWSTR* argv = CommandLineToArgvW(cmdLine, &argc); + + if (argv != NULL) { + for (int i = 0; i < argc; i++) { + char buffer[MAX_PATH]; + WideCharToMultiByte(CP_ACP, 0, argv[i], -1, buffer, MAX_PATH, NULL, NULL); + commandLineArgs.push_back(buffer); + } + + LocalFree(argv); + } + + CloseHandle(hProcess); + + return commandLineArgs; +} +#endif +#if TARGET_PLATFORM_IOS + +std::vector TC_Port::getCommandLine(int64_t pid) +{ + vector args; + + int mib[3], argmax, nargs, c = 0; + size_t size; + char *procargs, *sp, *np, *cp; + int show_args = 1; + + mib[0] = CTL_KERN; + mib[1] = KERN_ARGMAX; + + size = sizeof(argmax); + if (sysctl(mib, 2, &argmax, &size, NULL, 0) == -1) { + goto ERROR_A; + } + + /* Allocate space for the arguments. */ + procargs = (char *)malloc(argmax); + if (procargs == NULL) { + goto ERROR_A; + } + + /* + * Make a sysctl() call to get the raw argument space of the process. + * The layout is documented in start.s, which is part of the Csu + * project. In summary, it looks like: + * + * /---------------\ 0x00000000 + * : : + * : : + * |---------------| + * | argc | + * |---------------| + * | arg[0] | + * |---------------| + * : : + * : : + * |---------------| + * | arg[argc - 1] | + * |---------------| + * | 0 | + * |---------------| + * | env[0] | + * |---------------| + * : : + * : : + * |---------------| + * | env[n] | + * |---------------| + * | 0 | + * |---------------| <-- Beginning of data returned by sysctl() is here. + * | argc | + * |---------------| + * | exec_path | + * |:::::::::::::::| + * | | + * | String area. | + * | | + * |---------------| <-- Top of stack. + * : : + * : : + * \---------------/ 0xffffffff + */ + mib[0] = CTL_KERN; + mib[1] = KERN_PROCARGS2; + mib[2] = pid; + + size = (size_t)argmax; + if (sysctl(mib, 3, procargs, &size, NULL, 0) == -1) { + goto ERROR_B; + } + + memcpy(&nargs, procargs, sizeof(nargs)); + cp = procargs + sizeof(nargs); + + /* Skip the saved exec_path. */ + for (; cp < &procargs[size]; cp++) { + if (*cp == '\0') { + /* End of exec_path reached. */ + break; + } + } + if (cp == &procargs[size]) { + goto ERROR_B; + } + + /* Skip trailing '\0' characters. */ + for (; cp < &procargs[size]; cp++) { + if (*cp != '\0') { + /* Beginning of first argument reached. */ + break; + } + } + if (cp == &procargs[size]) { + goto ERROR_B; + } + /* Save where the argv[0] string starts. */ + sp = cp; + + /* + * Iterate through the '\0'-terminated strings and convert '\0' to ' ' + * until a string is found that has a '=' character in it (or there are + * no more strings in procargs). There is no way to deterministically + * know where the command arguments end and the environment strings + * start, which is why the '=' character is searched for as a heuristic. + */ + for (np = NULL; c < nargs && cp < &procargs[size]; cp++) { + if (*cp == '\0') { + c++; + if (np != NULL) { + /* Convert previous '\0'. */ + *np = ' '; + } else { + /* *argv0len = cp - sp; */ + } + /* Note location of current '\0'. */ + np = cp; + + if (!show_args) { + /* + * Don't convert '\0' characters to ' '. + * However, we needed to know that the + * command name was terminated, which we + * now know. + */ + break; + } + } + } + + /* + * sp points to the beginning of the arguments/environment string, and + * np should point to the '\0' terminator for the string. + */ + if (np == NULL || np == sp) { + /* Empty or unterminated string. */ + goto ERROR_B; + } + + /* Make a copy of the string. */ +// printf("%s\n", sp); + + args.push_back(sp); + + /* Clean up. */ + free(procargs); + return args; + + ERROR_B: + free(procargs); + ERROR_A: + + return args; +} +#endif +vector TC_Port::getPidsByCmdline(const string &cmdLine, bool accurateMatch) +{ + vector pids; + +#if TARGET_PLATFORM_IOS + int mib[4]; + mib[0] = CTL_KERN; + mib[1] = KERN_PROC; + mib[2] = KERN_PROC_ALL; + mib[3] = 0; + + size_t size; + if (sysctl(mib, 4, NULL, &size, NULL, 0) == -1) { + return {}; + } + + struct kinfo_proc* proc_list = (struct kinfo_proc*)malloc(size); + if (proc_list == NULL) { + return {}; + } + + if (sysctl(mib, 4, proc_list, &size, NULL, 0) == -1) { + free(proc_list); + return {}; + } + + int num_procs = size / sizeof(struct kinfo_proc); + for (int i = 0; i < num_procs; i++) + { + vector args = getCommandLine(proc_list[i].kp_proc.p_pid); + string path = TC_Common::tostr(args.begin(), args.end(), " "); + + if(accurateMatch) + { + if(cmdLine == path) + { + pids.push_back(proc_list[i].kp_proc.p_pid); + } + } + else + { + if(std::string(path).find(cmdLine) != std::string::npos) + { + pids.push_back(proc_list[i].kp_proc.p_pid); + } + } + } + + free(proc_list); + + return pids; +#elif TARGET_PLATFORM_LINUX + DIR* dir = opendir("/proc"); + if (!dir) { + return pids; + } + + struct dirent* entry; + while ((entry = readdir(dir)) != nullptr) + { + if(TC_Common::isdigit(entry->d_name)) + { + int64_t pid = TC_Common::strto(entry->d_name); + vector args = getCommandLine(pid); + string path = TC_Common::tostr(args.begin(), args.end(), " "); + + if(accurateMatch) + { + if(cmdLine == path) + { + pids.push_back(pid); + } + } + else + { + if(path.find(cmdLine) != std::string::npos) + { + pids.push_back(pid); + } + } + } + } + + closedir(dir); + return pids; +#elif TARGET_PLATFORM_WINDOWS + + HANDLE hProcessSnap; + PROCESSENTRY32 pe32; + + hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if (hProcessSnap == INVALID_HANDLE_VALUE) { + return pids; + } + + pe32.dwSize = sizeof(PROCESSENTRY32); + + if (!Process32First(hProcessSnap, &pe32)) { + CloseHandle(hProcessSnap); + return pids; + } + + // std::wstring wcmdLine(cmdLine.begin(), cmdLine.end()); + + do { + if(accurateMatch) + { + if(cmdLine == pe32.szExeFile) + { + pids.push_back(pe32.th32ProcessID); + } + } + else + { + if(std::string(pe32.szExeFile).find(cmdLine) != std::string::npos) + { + pids.push_back( pe32.th32ProcessID); + } + } + + } while (Process32Next(hProcessSnap, &pe32)); + + CloseHandle(hProcessSnap); + + return pids; +#else + return {}; +#endif +} + +FILE *TC_Port::freopen(const char * dst, const char * mode, FILE * src) +{ +#if TARGET_PLATFORM_IOS || TARGET_PLATFORM_WINDOWS + return ::freopen(dst, mode, src); +#else + return ::freopen64(dst, mode, src); +#endif } int64_t TC_Port::forkExec(const string& sExePath, const string& sPwdPath, const string& sRollLogPath, const vector& vOptions) @@ -313,11 +764,14 @@ int64_t TC_Port::forkExec(const string& sExePath, const string& sPwdPath, const } string command = sExePath + " " + path; - + // std::wstring wcommand(command.begin(), command.end()); + TCHAR p[1024]; - strncpy_s(p, sizeof(p) / sizeof(TCHAR), command.c_str(), command.length()); - - STARTUPINFO si; + strncpy_s(p, sizeof(p)/sizeof(TCHAR), command.c_str(), command.size()); + + // std::wstring wsPwdPath(sPwdPath.begin(), sPwdPath.end()); + + STARTUPINFOA si; memset(&si, 0, sizeof(si)); PROCESS_INFORMATION pi; memset(&pi, 0, sizeof(pi)); @@ -332,14 +786,12 @@ int64_t TC_Port::forkExec(const string& sExePath, const string& sPwdPath, const false, // 指示新进程是否从调用进程处继承了句柄。 CREATE_NEW_CONSOLE|CREATE_DEFAULT_ERROR_MODE | NORMAL_PRIORITY_CLASS | CREATE_NO_WINDOW, // 指定附加的、用来控制优先类和进程的创建的标 NULL, // 指向一个新进程的环境块。如果此参数为空,新进程使用调用进程的环境 - pwdCStr, // 指定子进程的工作路径 + sPwdPath.c_str(), // 指定子进程的工作路径 &si, // 决定新进程的主窗体如何显示的STARTUPINFO结构体 &pi // 接收新进程的识别信息的PROCESS_INFORMATION结构体 )) { - string err = TC_Exception::parseError(TC_Exception::getSystemCode()); - - throw TC_Port_Exception("[TC_Port::forkExec] CreateProcessA exception:" + err); + throw TC_Port_Exception("[TC_Port::forkExec] CreateProcessA exception:" + TC_Exception::getSystemError()); } CloseHandle(pi.hThread); @@ -348,8 +800,15 @@ int64_t TC_Port::forkExec(const string& sExePath, const string& sPwdPath, const return pi.dwProcessId; #else + + string bin = sExePath; + if(!TC_File::isAbsolute(bin)) + { + bin = TC_File::simplifyDirectory(TC_Port::getCwd() + FILE_SEP + bin); + } + vector vArgs; - vArgs.push_back(sExePath); + vArgs.push_back(bin); vArgs.insert(vArgs.end(), vOptions.begin(), vOptions.end()); int argc = static_cast(vArgs.size()); @@ -366,54 +825,28 @@ int64_t TC_Port::forkExec(const string& sExePath, const string& sPwdPath, const pid_t pid = fork(); if (pid == -1) { - throw TC_Port_Exception("[TC_Port::forkExec] fork exception"); + throw TC_Port_Exception("[TC_Port::forkExec] fork error:" + TC_Exception::getSystemError()); } if (pid == 0) { - int maxFd = static_cast(sysconf(_SC_OPEN_MAX)); - for (int fd = 3; fd < maxFd; ++fd) - { - close(fd); - } + closeAllFileDescriptors(); - //server stdcout 日志在滚动日志显示 + //stdout/stderr 重定向到日志文件里面 if (!sRollLogPath.empty()) { TC_File::makeDirRecursive(TC_File::extractFilePath(sRollLogPath)); -#if TARGET_PLATFORM_IOS - if ((freopen(sRollLogPath.c_str(), "ab", stdout)) != NULL && (freopen(sRollLogPath.c_str(), "ab", stderr)) != NULL) -#else - if ((freopen64(sRollLogPath.c_str(), "ab", stdout)) != NULL && (freopen64(sRollLogPath.c_str(), "ab", stderr)) != NULL) -#endif - { - cout << argv[0] << " redirect stdout and stderr to " << sRollLogPath << endl; - } - else - { - //重定向失败 直接退出 - exit(0); - } + TC_Port::freopen(sRollLogPath.c_str(), "ab", stdout); + TC_Port::freopen(sRollLogPath.c_str(), "ab", stderr); } - else - { - cout << argv[0] << " cannot redirect stdout and stderr to log file sRollLogPath is empty" << endl; - } - -// for_each(vEnvs.begin(), vEnvs.end(), EnvVal()); if (strlen(pwdCStr) != 0) { - if (chdir(pwdCStr) == -1) - { - cerr << argv[0] << " cannot change working directory to " << pwdCStr << "|errno=" << errno << endl; - } + chdir(pwdCStr); } - if (execvp(argv[0], argv) == -1) - { - cerr << "cannot execute " << argv[0] << "|errno=" << strerror(errno) << endl; - } + execvp(argv[0], argv); + exit(0); } else @@ -572,6 +1005,7 @@ BOOL WINAPI TC_Port::HandlerRoutine(DWORD dwCtrlType) } #endif +#if TARGET_PLATFORM_LINUX static int64_t reSize(int64_t i, const char unit) { @@ -588,8 +1022,64 @@ static int64_t reSize(int64_t i, const char unit) } return i; } +#endif + +double TC_Port::getCpuLoad(uint32_t queryTime) +{ +#if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS + double loadAvg[3]; + if ( getloadavg( loadAvg, 3 ) != -1 ) + { + return static_cast( loadAvg[0] ); + } + return -1; +#else + PDH_HQUERY cpuQuery; + PDH_HCOUNTER cpuTotal; + + // Initialize the PDH query + if (PdhOpenQuery(NULL, NULL, &cpuQuery) != ERROR_SUCCESS) { + return -1; + } + + // Add the CPU Time counter to the query + if (PdhAddCounter(cpuQuery, "\\Processor(_Total)\\% Processor Time", NULL, &cpuTotal) != ERROR_SUCCESS) { + return -1; + } + + // Collect the query data + if (PdhCollectQueryData(cpuQuery) != ERROR_SUCCESS) { + return -1; + } + + // Wait for some time + TC_Common::msleep(queryTime); -// 获取指定进程占用物理内存大小, 单位(字节) + // Collect the updated query data + if (PdhCollectQueryData(cpuQuery) != ERROR_SUCCESS) { + return -1; + } + + // Get the collected data + PDH_FMT_COUNTERVALUE counterVal; + + if (PdhGetFormattedCounterValue(cpuTotal, PDH_FMT_DOUBLE, NULL, &counterVal) != ERROR_SUCCESS) { + return -1; + } + + // Print the CPU usage +// std::cout << "CPU Usage: " << counterVal.doubleValue << " %\n"; + + // Close the query + if (PdhCloseQuery(cpuQuery) != ERROR_SUCCESS) { + return -1; + } + + return counterVal.doubleValue; +#endif +} + +// 获取指定进程占用物理内存大小 int64_t TC_Port::getPidMemUsed(int64_t pid, const char unit) { #if TARGET_PLATFORM_LINUX @@ -605,11 +1095,66 @@ int64_t TC_Port::getPidMemUsed(int64_t pid, const char unit) } } return -1; -#else - return -1; +#elif TARGET_PLATFORM_IOS + struct proc_taskinfo procInfo; + int ret = proc_pidinfo(pid, PROC_PIDTASKINFO, 0, &procInfo, PROC_PIDTASKINFO_SIZE); + if (ret <= 0) { + return -1; + } + + int64_t memUsed = procInfo.pti_resident_size; + + // Apply unit conversion if necessary + switch (unit) { + case 'K': // KB + memUsed /= 1024; + break; + case 'G': // GB + memUsed /= (1024 * 1024 * 1024); + break; + case 'M': // MB + memUsed /= (1024 * 1024); + break; + default: + break; + } + + return memUsed; +#elif TARGET_PLATFORM_WINDOWS + HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); + if (processHandle == NULL) { + return -1; + } + + PROCESS_MEMORY_COUNTERS pmc; + if (!GetProcessMemoryInfo(processHandle, &pmc, sizeof(pmc))) { + CloseHandle(processHandle); + return -1; + } + + CloseHandle(processHandle); + int64_t memUsed = pmc.WorkingSetSize; + + // Apply unit conversion if necessary + switch (unit) { + case 'K': // KB + memUsed /= 1024; + break; + case 'G': // GB + memUsed /= (1024 * 1024 * 1024); + break; + case 'M': // MB + memUsed /= (1024 * 1024); + break; + default: + break; + } + + return memUsed; #endif } +//服务器启动时间 time_t TC_Port::getUPTime() { #if TARGET_PLATFORM_LINUX @@ -624,8 +1169,22 @@ time_t TC_Port::getUPTime() return TNOW - (time_t)(TC_Common::strto(vs[0])); -#else - return 0; +#elif TARGET_PLATFORM_IOS + struct timeval boottime; + size_t size = sizeof(boottime); + int mib[2] = { CTL_KERN, KERN_BOOTTIME }; + if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 && boottime.tv_sec != 0) { + time_t bsec = boottime.tv_sec;//, busec = boottime.tv_usec; +// time_t now = time(NULL); + return bsec; + } else { + return 0; + } + +#elif TARGET_PLATFORM_WINDOWS + ULONGLONG tickCount = GetTickCount64(); + time_t upTime = tickCount / 1000; + return upTime; #endif } @@ -647,8 +1206,45 @@ time_t TC_Port::getPidStartTime(int64_t pid) return 0; } return bootTime + duration; -#else - return -1; +#elif TARGET_PLATFORM_IOS + struct proc_taskallinfo allinfo; + int ret = proc_pidinfo(pid, PROC_PIDTASKALLINFO, 0, &allinfo, sizeof(allinfo)); + if (ret <= 0) { + return -1; + } + + // Convert the process start time from absolute time to seconds since the Epoch + time_t startTime = allinfo.pbsd.pbi_start_tvsec + allinfo.pbsd.pbi_start_tvusec / 1e6; + return startTime; +#elif TARGET_PLATFORM_WINDOWS + HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); + if(h == INVALID_HANDLE_VALUE) { + return -1; + } + + PROCESSENTRY32 pe = { 0 }; + pe.dwSize = sizeof(PROCESSENTRY32); + if(!Process32First(h, &pe)) { + CloseHandle(h); + return -1; + } + + do { + if(pe.th32ProcessID == pid) { + FILETIME ftCreate, ftExit, ftKernel, ftUser; + if (GetProcessTimes(h, &ftCreate, &ftExit, &ftKernel, &ftUser)) { + ULARGE_INTEGER uli; + uli.LowPart = ftCreate.dwLowDateTime; + uli.HighPart = ftCreate.dwHighDateTime; + time_t startTime = (uli.QuadPart / 10000000ULL - 11644473600ULL); + CloseHandle(h); + return startTime; + } + } + } while(Process32Next(h, &pe)); + + CloseHandle(h); + return -1; #endif } @@ -709,42 +1305,152 @@ bool TC_Port::getSystemMemInfo(int64_t &totalSize, int64_t &availableSize, float totalSize = reSize(total, unit); availableSize = reSize(available, unit); return true; -#else - return false; +#elif TARGET_PLATFORM_IOS + int mib[2]; + int64_t physical_memory; + size_t length; + mib[0] = CTL_HW; + mib[1] = HW_MEMSIZE; + length = sizeof(int64_t); + sysctl(mib, 2, &physical_memory, &length, NULL, 0); + + vm_statistics64_data_t vmstat; + mach_msg_type_number_t count = sizeof(vmstat) / sizeof(natural_t); + if(KERN_SUCCESS != host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t)&vmstat, &count)){ + return false; + } + + totalSize = physical_memory; + availableSize = vmstat.free_count * vm_page_size; + + if (totalSize == 0) { + return false; + } + + usedPercent = ((totalSize - availableSize) * 100.0) / totalSize; + + // Apply unit conversion if necessary + switch (unit) { + case 'K': // KB + totalSize /= 1024; + availableSize /= 1024; + break; + case 'G': // GB + totalSize /= (1024 * 1024 * 1024); + availableSize /= (1024 * 1024 * 1024); + break; + case 'M': // MB + totalSize /= (1024 * 1024); + availableSize /= (1024 * 1024); + break; + default: + break; + } + + return true; +#elif TARGET_PLATFORM_WINDOWS + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(MEMORYSTATUSEX); + if (!GlobalMemoryStatusEx(&memInfo)) { + return false; + } + + totalSize = memInfo.ullTotalPhys / (1024 * 1024); // Convert to MB + availableSize = memInfo.ullAvailPhys / (1024 * 1024); // Convert to MB + + if (totalSize == 0) { + return false; + } + + usedPercent = ((totalSize - availableSize) * 100.0) / totalSize; + + // Apply unit conversion if necessary + switch (unit) { + case 'K': // KB + totalSize *= 1024; + availableSize *= 1024; + break; + case 'G': // GB + totalSize /= 1024; + availableSize /= 1024; + break; + // case 'M': // MB - no conversion necessary + default: + break; + } + + return true; #endif } // 获取系统CPU核数 int TC_Port::getCPUProcessor() { -#if TARGET_PLATFORM_LINUX - return get_nprocs(); +#if TARGET_PLATFORM_WINDOWS + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; +#elif TARGET_PLATFORM_IOS + int nm[2]; + size_t len = 4; + uint32_t count; + + nm[0] = CTL_HW; + nm[1] = HW_AVAILCPU; + sysctl(nm, 2, &count, &len, NULL, 0); + + if (count < 1) { + nm[1] = HW_NCPU; + sysctl(nm, 2, &count, &len, NULL, 0); + if (count < 1) { count = 1; } + } + return count; #else - return -1; + return get_nprocs(); #endif } -bool TC_Port::getDiskInfo(float& usedPercent, int64_t& availableSize, const string& path) +bool TC_Port::getDiskInfo(int64_t &totalSize, int64_t& availableSize, float& usedPercent, const string& path) { -#if TARGET_PLATFORM_LINUX - struct statfs64 buf; +#if TARGET_PLATFORM_WINDOWS + ULARGE_INTEGER freeBytesAvailableToCaller; + ULARGE_INTEGER totalNumberOfBytes; + ULARGE_INTEGER totalNumberOfFreeBytes; - if(statfs64(path.c_str(),&buf)==-1) - { - return false; - } + // std::wstring wpath(path.begin(), path.end()); - size_t totalSize = (buf.f_blocks / 1024) * (buf.f_bsize / 1024); - if (totalSize == 0) - { - return false; - } + if (!GetDiskFreeSpaceEx(path.c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) { + return false; + } - availableSize = (buf.f_bavail / 1024) * (buf.f_bsize / 1024); - usedPercent = (totalSize - availableSize) * 1.0 / totalSize * 100; - return true; + totalSize = totalNumberOfBytes.QuadPart; + ULONGLONG freeSize = totalNumberOfFreeBytes.QuadPart; + + if (totalSize == 0) { + return false; + } + + availableSize = freeSize; + usedPercent = (totalSize - freeSize) * 100.0 / totalSize; + + return true; #else - return false; + struct statfs64 buf; + + if(statfs64(path.c_str(),&buf)==-1) + { + return false; + } + + totalSize = buf.f_blocks * buf.f_bsize; + if (totalSize == 0) + { + return false; + } + + availableSize = buf.f_bavail * buf.f_bsize; + usedPercent = (totalSize - availableSize) * 1.0 / totalSize * 100; + return true; #endif } diff --git a/util/src/tc_socket.cpp b/util/src/tc_socket.cpp index f81946bf..79fe975b 100755 --- a/util/src/tc_socket.cpp +++ b/util/src/tc_socket.cpp @@ -141,7 +141,7 @@ void TC_Socket::bind(const char *sPathName) struct sockaddr_un stBindAddr; memset(&stBindAddr, 0x00, sizeof(stBindAddr)); stBindAddr.sun_family = _iDomain; - strncpy(stBindAddr.sun_path, sPathName, sizeof(stBindAddr.sun_path)); + strncpy(stBindAddr.sun_path, sPathName, sizeof(stBindAddr.sun_path)-1); try { @@ -171,7 +171,7 @@ int TC_Socket::connectNoThrow(const char *sPathName) struct sockaddr_un stServerAddr; memset(&stServerAddr, 0x00, sizeof(stServerAddr)); stServerAddr.sun_family = _iDomain; - strncpy(stServerAddr.sun_path, sPathName, sizeof(stServerAddr.sun_path)); + strncpy(stServerAddr.sun_path, sPathName, sizeof(stServerAddr.sun_path)-1); return connect((struct sockaddr *)&stServerAddr, sizeof(stServerAddr)); } @@ -417,7 +417,7 @@ void TC_Socket::parseUnixLocalAddr(const char* sPathName, struct sockaddr_un& ad { memset(&addr, 0x00, sizeof(addr)); addr.sun_family = AF_LOCAL; - strncpy(addr.sun_path, sPathName, sizeof(addr.sun_path)); + strncpy(addr.sun_path, sPathName, sizeof(addr.sun_path)-1); } #endif @@ -889,154 +889,55 @@ void TC_Socket::createPipe(int fds[2], bool bBlock) if (tcp1 != -1) { TC_Port::closeSocket(tcp1); } -// #if TARGET_PLATFORM_LINUX||TARGET_PLATFORM_IOS -// #undef closesocket -// #endif + THROW_EXCEPTION_SYSCODE(TC_Socket_Exception, "[TC_Socket::createPipe] error"); } -#if TARGET_PLATFORM_LINUX -vector TC_Socket::getLocalHosts(int domain) +vector TC_Socket::getLocalHosts(int domain, bool withLoopIp) { - vector result; - TC_Socket ts; - ts.createSocket(SOCK_STREAM, domain); - - int cmd = SIOCGIFCONF; - - struct ifconf ifc; - - int numaddrs = 10; + vector hosts; + char local[255] = { 0 }; + gethostname(local, sizeof(local)); - int old_ifc_len = 0; + struct addrinfo hints, *res, *p; + int status; + char ipstr[INET6_ADDRSTRLEN] = {0}; - while(true) - { - int bufsize = numaddrs * static_cast(sizeof(struct ifreq)); - ifc.ifc_len = bufsize; - ifc.ifc_buf = (char*)malloc(bufsize); - int rs = ioctl(ts.getfd(), cmd, &ifc); + memset(&hints, 0, sizeof hints); + hints.ai_family = domain; // AF_UNSPEC means any: AF_INET, AF_INET6, etc. + hints.ai_socktype = SOCK_STREAM; - if(rs == -1) - { - free(ifc.ifc_buf); - throw TC_Socket_Exception("[TC_Socket::getLocalHosts] ioctl error", errno); - } - else if(ifc.ifc_len == old_ifc_len) - { - break; - } - else - { - old_ifc_len = ifc.ifc_len; - } - - numaddrs += 10; - free(ifc.ifc_buf); + if ((status = getaddrinfo(local, NULL, &hints, &res)) != 0) { + return hosts; } - numaddrs = ifc.ifc_len / static_cast(sizeof(struct ifreq)); - struct ifreq* ifr = ifc.ifc_req; - for(int i = 0; i < numaddrs; ++i) - { - if(ifr[i].ifr_addr.sa_family == AF_INET) - { - struct sockaddr_in* addr = reinterpret_cast(&ifr[i].ifr_addr); - if(addr->sin_addr.s_addr != 0) - { - char sAddr[INET_ADDRSTRLEN] = "\0"; - inet_ntop(AF_INET, &(*addr).sin_addr, sAddr, sizeof(sAddr)); - result.push_back(sAddr); - } + for(p = res;p != NULL; p = p->ai_next) { + void *addr; + if (p->ai_family == AF_INET) { // IPv4 + struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr; + addr = &(ipv4->sin_addr); + } else if (p->ai_family == AF_INET6) { // IPv6 + struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr; + addr = &(ipv6->sin6_addr); } - else if (ifr[i].ifr_addr.sa_family == AF_INET6) + else { - struct sockaddr_in6* addr = reinterpret_cast(&ifr[i].ifr_addr); - if(!memcmp(&addr->sin6_addr, &in6addr_any, sizeof(addr->sin6_addr))) - { - char sAddr[INET6_ADDRSTRLEN] = "\0"; - inet_ntop(AF_INET6, &(*addr).sin6_addr, sAddr, sizeof(sAddr)); - result.push_back(sAddr); - } + continue; } - } - - free(ifc.ifc_buf); - - return result; -} -#elif TARGET_PLATFORM_IOS -vector TC_Socket::getLocalHosts(int domain) -{ - vector hosts; - char local[255] = { 0 }; - gethostname(local, sizeof(local)); - hostent* ph = gethostbyname(local); - if (ph == NULL) - { - return hosts; - } - in_addr addr; - if (ph->h_addrtype == AF_INET) - { - int i = 0; - while (ph->h_addr_list[i] != 0) + // convert IP to a string and add it to the list + inet_ntop(p->ai_family, addr, ipstr, sizeof(ipstr)); + if(withLoopIp || (TC_Port::strcasecmp(ipstr,"127.0.0.1") != 0 && TC_Port::strcasecmp(ipstr, "::1") != 0)) { - addr.s_addr = *(u_long*)ph->h_addr_list[i++]; - hosts.emplace_back(inet_ntoa(addr)); + hosts.emplace_back(ipstr); } } - else - { - // unsupport AF_INET6 ... - return hosts; - } - return hosts; -} -#endif - -#if TARGET_PLATFORM_WINDOWS -vector TC_Socket::getLocalHosts(int domain) -{ - vector hosts; - WORD wVersionRequested = MAKEWORD(2, 2); - WSADATA wsaData; - if (WSAStartup(wVersionRequested, &wsaData) != 0) - { - return hosts; - } + freeaddrinfo(res); - char local[255] = { 0 }; - gethostname(local, sizeof(local)); - hostent* ph = gethostbyname(local); - if (ph == NULL) - { - return hosts; - } - - in_addr addr; - if (ph->h_addrtype == AF_INET) - { - int i = 0; - while (ph->h_addr_list[i] != 0) - { - addr.s_addr = *(u_long*)ph->h_addr_list[i++]; - hosts.emplace_back(inet_ntoa(addr)); - } - } - else - { - // unsupport AF_INET6 ... - return hosts; - } - WSACleanup(); return hosts; } -#endif - bool TC_Socket::isPending() { #if TARGET_PLATFORM_WINDOWS diff --git a/util/src/tc_thread.cpp b/util/src/tc_thread.cpp index 8ac8d54a..ccf92ba3 100644 --- a/util/src/tc_thread.cpp +++ b/util/src/tc_thread.cpp @@ -123,7 +123,7 @@ void TC_Thread::threadEntry(TC_Thread *pThread) catch (exception &ex) { cerr << std::this_thread::get_id() << "|" << ex.what() << endl; - throw ex; + throw; } catch (...) { diff --git a/util/src/tc_transceiver.cpp b/util/src/tc_transceiver.cpp index 46bb4a54..2fee18bd 100644 --- a/util/src/tc_transceiver.cpp +++ b/util/src/tc_transceiver.cpp @@ -1044,8 +1044,9 @@ int TC_TCPTransceiver::send(const void* buf, uint32_t len, uint32_t flag) if (iRet < 0 && !TC_Socket::isPending()) { - THROW_ERROR(TC_Transceiver_Exception, CR_SEND, - "TC_TCPTransceiver::send, " + _desc + ", fd:" + TC_Common::tostr(_fd)); + tcpClose(false, CR_SEND, "TC_TCPTransceiver::send, " + _desc + ", fd:" + TC_Common::tostr(_fd)); + return -1; +// THROW_ERROR(TC_Transceiver_Exception, CR_SEND, "TC_TCPTransceiver::send, " + _desc + ", fd:" + TC_Common::tostr(_fd)); } #if TARGET_PLATFORM_WINDOWS