diff --git a/CMakeLists.txt b/CMakeLists.txt index 71b413ff..03531a40 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,17 +20,15 @@ if("${TARS_CPP_COMMON}" STREQUAL "") endif() -# set(major "") -# set(minor "") -# set(patch "") -# get_version(major minor patch) - -# set(TARS_VERSION ${major}.${minor}.${patch}) - add_definitions(-DTARS_VERSION="${TARS_VERSION}") - message("TARS_VERSION: ${TARS_VERSION}") +# if(WIN32) +# option(ENABLE_MT "option for /MT" ON) +# include(${PROJECT_SOURCE_DIR}/cmake/compiler_flags_overrides.cmake) +# message("ENABLE_MT: ${ENABLE_MT}") +# endif(WIN32) + set(CLEAR_INCLUDE "clear-install.cmake") FILE(WRITE ${CLEAR_INCLUDE} "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E remove_directory ${CMAKE_INSTALL_PREFIX}/include)\n") install(SCRIPT ${CLEAR_INCLUDE}) diff --git a/Changelist-3.x.md b/Changelist-3.x.md index 59f11572..4343f4b4 100644 --- a/Changelist-3.x.md +++ b/Changelist-3.x.md @@ -1,3 +1,86 @@ +# v3.0.18 20231106 +### en +- fix: udp ipv6 bug +- fix: unit-test get fd counts in mac +- fix: udp send/recv bug when multi net threads in communicator +- fix: servanthandle only keep one servant +- fix: cmake /SAFESEH:NO +- fix: cmake -fsigned-char only in unix +- fix: epoll server fd leak in co mode +- fix: tc_logger snprintf compiler warning +- fix: epoll server queue mode in co mode +- fix: cmake CMAKE_INSTALL_PREFIX +- update NotifyF.tars, delete some interface not used +- Optimize the initialization process of Current to improve performance +- feat: Application add: getBindAdapter by obj +- not compiler gtest mock(mac latest gcc gtest can not compiler) +- support arm32 compiler +- support cpu(i686) compiler +- support arm cross compiler(CMAKE_TOOLCHAIN_FILE) + +### cn +- 修复: udp ipv6的bug +- 修复: mac下unit-test中fd的计算 +- 修复: 多线程的通信器模式下, udp收发包的bug +- 修复: ServantHandle只保留一个Servant, 提高性能 +- 修复: cmake /SAFESEH:NO +- 修复: cmake 默认打开-fsigned-char, 避免arm下编译的问题 +- 修复: epollserver 在协程模式下句柄的泄露(不影响业务) +- 修复: tc_logger snprintf 中的编译警告 +- 修复: epoll server队列模式在协程模式下的bug +- 修复: cmake CMAKE_INSTALL_PREFIX +- 更新NotifyF.tars, 删除了不再使用的接口 +- 优化了Current初始化过程, 提高性能 +- Application添加根据obj获取BindAdapter的函数: getBindAdapter +- 不再编译gtest mock +- 支持arm32的编译 +- 支持cpu为i686的编译 +- 支持了arm交叉编译, 支持CMAKE_TOOLCHAIN_FILE +- +# v3.0.17 20231007 +### en +- fix remote logger, set _logStatReport default value +- fix time logger crash bug when comm not initialize +- fix cmake clear install +- fix tc_json double bug +- fix commumicator ssl ctx init bug +- fix tc_socket sizeof duplicate bug +- fix push callbak onClose(ep) +- fix http_call request use const +- fix ServantProxy::invoke crash on QiLin OS +- tc_autoptr add staticCast +- open /MT in windows by default +- push callback add onConnected +- tarsregistry update self ip list +- ServantProxy add tars_close, close fd of prx +- hash code type use size_t +- set max tars package size 100M +- add tc_timeout_queue_map(key value cache+queue) +- add tc_socket_async +- Update Contributing.md + +### cn +- 修复: 远程日志未设置_logStatReport缺省值的问题 +- 修复: 通信器未初始化时, 按天日志可能会crash的问题 +- 修复: cmake清除installde问题 +- 修复: tc_json double类型解析的bug +- 修复: 通信器ssl ctx初始化的问题 +- 修复: tc_socket中使用sizeof有误的问题 +- 修复: push callbak中onClose(ep)没有被回调的问题 +- 修复: http_call请求参数使用const +- 修复: 在麒麟OS上, ServantProxy::invoke 的 crash +- tc_autoptr 添加 staticCast +- windows编译默认开启/MT +- push callback 添加 onConnected回调 +- tarsregistry更新自己的ip list +- ServantProxy 添加了tars_close, 关闭自己的句柄 +- hash code 类型统一修改为 size_t +- 最大网络包调整为100M +- +- 添加工具类: tc_timeout_queue_map(key value cache+queue) +- 添加工具类: tc_socket_async +- 修改Contributing.md + # v3.0.16 20230810 ### en - please notice!!!! default value of bool in tars struct set to false diff --git a/Contributing.md b/Contributing.md index 8607acdc..adc86e2e 100644 --- a/Contributing.md +++ b/Contributing.md @@ -14,3 +14,5 @@ If you contributed but cannot find your ID here, please submit PR and add your G - viest - YMChenLiye - zhanleewo +- BeyondWUXF +- diff --git a/cmake/BuildTarsCpp.cmake b/cmake/BuildTarsCpp.cmake index c1228b95..b12af256 100755 --- a/cmake/BuildTarsCpp.cmake +++ b/cmake/BuildTarsCpp.cmake @@ -98,9 +98,9 @@ macro(build_tars_server MODULE DEPS) target_link_libraries(${MODULE} ${LIB_HTTP2} ${LIB_PROTOBUF}) endif() - if(TARS_GPERF) - target_link_libraries(${MODULE} ${LIB_GPERF}) - endif(TARS_GPERF) +# if(TARS_GPERF) +# target_link_libraries(${MODULE} ${LIB_GPERF}) +# endif(TARS_GPERF) SET(MODULE-TGZ "${CMAKE_BINARY_DIR}/${MODULE}.tgz") SET(RUN_DEPLOY_COMMAND_FILE "${PROJECT_BINARY_DIR}/run-deploy-${MODULE}.cmake") diff --git a/cmake/Common.cmake b/cmake/Common.cmake index 4594fdce..e8e3817d 100755 --- a/cmake/Common.cmake +++ b/cmake/Common.cmake @@ -1,6 +1,6 @@ -set(TARS_VERSION "3.0.16") +set(TARS_VERSION "3.0.18") add_definitions(-DTARS_VERSION="${TARS_VERSION}") set(CMAKE_VERBOSE_MAKEFILE off) @@ -40,11 +40,16 @@ option(ONLY_LIB "option for only lib" ON) #------------------------------------------------------------- IF (UNIX) - set(CMAKE_INSTALL_PREFIX "/usr/local/tars/cpp" CACHE STRING "set install path" FORCE) + set(INSTALL_PREFIX "/usr/local/tars/cpp" CACHE STRING "set install path" ) ELSE() - set(CMAKE_INSTALL_PREFIX "c:\\tars\\cpp" CACHE STRING "set install path" FORCE) + set(INSTALL_PREFIX "c:/tars/cpp" CACHE STRING "set install path") ENDIF() +#工程INSTALL目录 +IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${INSTALL_PREFIX}" CACHE STRING "set install path" FORCE) +endif() + #------------------------------------------------------------- IF (APPLE) link_libraries(iconv) @@ -60,8 +65,8 @@ ENDIF() set(PLATFORM) IF (UNIX) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++11 -Wno-deprecated -fno-strict-aliasing -Wno-overloaded-virtual") + 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_DEBUG "$ENV{CXXFLAGS} -Wall -g") @@ -78,19 +83,30 @@ IF (UNIX) ELSEIF (WIN32) set(PLATFORM "window") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4101 /wd4244 /wd4996 /wd4091 /wd4503 /wd4819 /wd4200 /wd4800 /wd4267 /wd4834 /wd4267") - 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") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /bigobj" ) + + SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") + SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") + SET (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO") + + #Release生成PDB + SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /OPT:ICF /OPT:REF /DEBUG") + 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") ELSE () MESSAGE(STATUS "================ ERROR: This platform is unsupported!!! ================") ENDIF (UNIX) +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char") + IF (WIN32) add_definitions(-DNOMINMAX) ENDIF () #------------------------------------------------------------- -set(TARS2CPP "${CMAKE_BINARY_DIR}/bin/tars2cpp") +set(TARS2CPP "${CMAKE_BINARY_DIR}/bin/tars2cpp" CACHE STRING "set tars2cpp") message("----------------------------------------------------") message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}") diff --git a/cmake/ParseAsm.cmake b/cmake/ParseAsm.cmake index d8af081c..21e6714a 100644 --- a/cmake/ParseAsm.cmake +++ b/cmake/ParseAsm.cmake @@ -5,6 +5,8 @@ set(CPU_STR "combined") if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386") set(CPU_STR "i386") +elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686") + set(CPU_STR "i386") elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") set(CPU_STR "x86_64") elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") diff --git a/cmake/Thirdparty.cmake b/cmake/Thirdparty.cmake index 10a0e7d2..10c373e5 100755 --- a/cmake/Thirdparty.cmake +++ b/cmake/Thirdparty.cmake @@ -1,30 +1,39 @@ option(TARS_MYSQL "option for mysql" ON) +if(UNIX) +option(TARS_GZIP "option for gzip" ON) +else(UNIX) +option(TARS_GZIP "option for gzip" OFF) +endif(UNIX) option(TARS_SSL "option for ssl" OFF) option(TARS_HTTP2 "option for http2" OFF) option(TARS_PROTOBUF "option for protocol" OFF) -option(TARS_GPERF "option for gperf" OFF) - -IF(UNIX) - FIND_PACKAGE(ZLIB) - IF(NOT ZLIB_FOUND) - SET(ERRORMSG "zlib library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.") - IF(CMAKE_SYSTEM_NAME MATCHES "Linux") - SET(ERRORMSG ${ERRORMSG} "On Debian/Ubuntu, package name is zlib1g-dev(apt-get install zlib1g-dev), on Redhat/Centos and derivates it is zlib-devel (yum install zlib-devel).") - ENDIF() - MESSAGE(FATAL_ERROR ${ERRORMSG}) - ENDIF() - -ENDIF(UNIX) +#option(TARS_GPERF "option for gperf" OFF) + +#IF(UNIX) +# FIND_PACKAGE(ZLIB) +# IF(NOT ZLIB_FOUND) +# SET(ERRORMSG "zlib library not found. Please install appropriate package, remove CMakeCache.txt and rerun cmake.") +# IF(CMAKE_SYSTEM_NAME MATCHES "Linux") +# SET(ERRORMSG ${ERRORMSG} "On Debian/Ubuntu, package name is zlib1g-dev(apt-get install zlib1g-dev), on Redhat/Centos and derivates it is zlib-devel (yum install zlib-devel).") +# ENDIF() +# MESSAGE(FATAL_ERROR ${ERRORMSG}) +# ENDIF() +# +#ENDIF(UNIX) if (TARS_MYSQL) add_definitions(-DTARS_MYSQL=1) endif () -if (TARS_GPERF) - add_definitions(-DTARS_GPERF=1) +if (TARS_GZIP) + add_definitions(-DTARS_GZIP=1) endif () +#if (TARS_GPERF) +# add_definitions(-DTARS_GPERF=1) +#endif () + if (TARS_SSL) add_definitions(-DTARS_SSL=1) endif () @@ -42,56 +51,56 @@ endif () set(THIRDPARTY_PATH "${CMAKE_BINARY_DIR}/src") set(LIB_MYSQL) +set(LIB_GZIP) set(LIB_HTTP2) set(LIB_SSL) set(LIB_CRYPTO) set(LIB_PROTOBUF) set(LIB_GTEST) -set(LIB_GPERF) -set(LIB_TCMALLOC_PROFILER) -set(LIB_TCMALLOC_MINIMAL) +#set(LIB_GPERF) +#set(LIB_TCMALLOC_PROFILER) +#set(LIB_TCMALLOC_MINIMAL) #------------------------------------------------------------- add_custom_target(thirdparty) include(ExternalProject) - -if (TARS_GPERF) - - set(GPERF_DIR_INC "${THIRDPARTY_PATH}/gperf/include") - set(GRPEF_DIR_LIB "${THIRDPARTY_PATH}/gperf/lib") - include_directories(${GPERF_DIR_INC}) - link_directories(${GRPEF_DIR_LIB}) - - if (UNIX) - set(LIB_GPERF "profiler") - set(LIB_TCMALLOC_PROFILER "tcmalloc_and_profiler") - set(LIB_TCMALLOC_MINIMAL "tcmalloc_and_minimal") - - ExternalProject_Add(ADD_${LIB_GPERF} - URL https://tars-thirdpart-1300910346.cos.ap-guangzhou.myqcloud.com//src/gperftools-2.7.tar.gz - DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download - PREFIX ${CMAKE_BINARY_DIR} - INSTALL_DIR ${CMAKE_SOURCE_DIR} - CONFIGURE_COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/src/gperf --disable-shared --disable-debugalloc - SOURCE_DIR ${CMAKE_BINARY_DIR}/src/gperf-lib - BUILD_IN_SOURCE 1 - BUILD_COMMAND make - # INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config release --target install - URL_MD5 c6a852a817e9160c79bdb2d3101b4601 - ) - - add_dependencies(thirdparty ADD_${LIB_GPERF}) - - INSTALL(FILES ${CMAKE_BINARY_DIR}/src/gperf/bin/pprof - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ - DESTINATION thirdparty/bin/) - INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/gperf/lib DESTINATION thirdparty) - INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/gperf/include/gperftools DESTINATION thirdparty/include) - - endif (UNIX) - -endif (TARS_GPERF) +# +#if (TARS_GPERF) +# +# set(GPERF_DIR_INC "${THIRDPARTY_PATH}/gperf/include") +# set(GRPEF_DIR_LIB "${THIRDPARTY_PATH}/gperf/lib") +# include_directories(${GPERF_DIR_INC}) +# link_directories(${GRPEF_DIR_LIB}) +# +# if (UNIX) +# set(LIB_GPERF "profiler") +# set(LIB_TCMALLOC_PROFILER "tcmalloc_and_profiler") +# set(LIB_TCMALLOC_MINIMAL "tcmalloc_and_minimal") +# +# ExternalProject_Add(ADD_${LIB_GPERF} +# URL https://tars-thirdpart-1300910346.cos.ap-guangzhou.myqcloud.com//src/gperftools-2.7.tar.gz +# DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download +# PREFIX ${CMAKE_BINARY_DIR} +# INSTALL_DIR ${CMAKE_SOURCE_DIR} +# CONFIGURE_COMMAND ./configure --prefix=${CMAKE_BINARY_DIR}/src/gperf --disable-shared --disable-debugalloc +# SOURCE_DIR ${CMAKE_BINARY_DIR}/src/gperf-lib +# BUILD_IN_SOURCE 1 +# BUILD_COMMAND make +# URL_MD5 c6a852a817e9160c79bdb2d3101b4601 +# ) +# +# add_dependencies(thirdparty ADD_${LIB_GPERF}) +# +# INSTALL(FILES ${CMAKE_BINARY_DIR}/src/gperf/bin/pprof +# PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ GROUP_EXECUTE GROUP_READ +# DESTINATION thirdparty/bin/) +# INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/gperf/lib DESTINATION thirdparty) +# INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/gperf/include/gperftools DESTINATION thirdparty/include) +# +# endif (UNIX) +# +#endif (TARS_GPERF) if(WIN32) @@ -126,7 +135,7 @@ if (WIN32) DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download PREFIX ${CMAKE_BINARY_DIR} INSTALL_DIR ${CMAKE_SOURCE_DIR} - CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/gtest -A x64 -Dgtest_force_shared_crt=on + CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/gtest -A x64 -Dgtest_force_shared_crt=on -DBUILD_GMOCK=OFF SOURCE_DIR ${CMAKE_BINARY_DIR}/src/gtest-lib BUILD_IN_SOURCE 1 BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE} @@ -141,7 +150,7 @@ else() 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/gtest + CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/gtest -DBUILD_GMOCK=OFF -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} SOURCE_DIR ${CMAKE_BINARY_DIR}/src/gtest-lib BUILD_IN_SOURCE 1 BUILD_COMMAND make @@ -186,7 +195,7 @@ if (TARS_PROTOBUF) DOWNLOAD_DIR ${CMAKE_SOURCE_DIR}/download PREFIX ${CMAKE_BINARY_DIR} INSTALL_DIR ${CMAKE_SOURCE_DIR} - CONFIGURE_COMMAND ${CMAKE_COMMAND} cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/protobuf -DBUILD_SHARED_LIBS=OFF + CONFIGURE_COMMAND ${CMAKE_COMMAND} cmake -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/protobuf -DBUILD_SHARED_LIBS=OFF -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} SOURCE_DIR ${CMAKE_BINARY_DIR}/src/protobuf-lib BUILD_IN_SOURCE 1 BUILD_COMMAND make @@ -279,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 + 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} SOURCE_DIR ${CMAKE_BINARY_DIR}/src/mysql-lib BUILD_IN_SOURCE 1 BUILD_COMMAND make mysqlclient @@ -295,6 +304,51 @@ if (TARS_MYSQL) endif () +if (TARS_GZIP) + set(GZIP_DIR_INC "${THIRDPARTY_PATH}/zlib/include") + set(GZIP_DIR_LIB "${THIRDPARTY_PATH}/zlib/lib") + include_directories(${GZIP_DIR_INC}) + link_directories(${GZIP_DIR_LIB}) + + if (WIN32) + set(LIB_GZIP "libz") + + ExternalProject_Add(ADD_${LIB_GZIP} + URL http://cdn.tarsyun.com/src/zlib-1.2.11.tar.gz + 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/zlib + SOURCE_DIR ${CMAKE_BINARY_DIR}/src/zlib-lib + BUILD_IN_SOURCE 1 + BUILD_COMMAND ${CMAKE_COMMAND} --build . --config release + INSTALL_COMMAND ${CMAKE_COMMAND} --build . --config release --target install + URL_MD5 1c9f62f0778697a09d36121ead88e08e + ) + + else () + set(LIB_GZIP "z") + + ExternalProject_Add(ADD_${LIB_GZIP} + URL http://cdn.tarsyun.com/src/zlib-1.2.11.tar.gz + 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/zlib -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} + SOURCE_DIR ${CMAKE_BINARY_DIR}/src/zlib-lib + BUILD_IN_SOURCE 1 + BUILD_COMMAND make + URL_MD5 1c9f62f0778697a09d36121ead88e08e + ) + + endif () + + INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/zlib/lib DESTINATION thirdparty) + INSTALL(DIRECTORY ${CMAKE_BINARY_DIR}/src/zlib/include/ DESTINATION thirdparty/include/zlib) + + add_dependencies(thirdparty ADD_${LIB_GZIP}) +endif () + if (TARS_HTTP2) set(NGHTTP2_DIR_INC "${THIRDPARTY_PATH}/nghttp2/include/") @@ -326,7 +380,7 @@ if (TARS_HTTP2) 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/nghttp2 -DENABLE_LIB_ONLY=ON -DENABLE_STATIC_LIB=ON + CONFIGURE_COMMAND ${CMAKE_COMMAND} . -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/src/nghttp2 -DENABLE_LIB_ONLY=ON -DENABLE_STATIC_LIB=ON -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} SOURCE_DIR ${CMAKE_BINARY_DIR}/src/nghttp2-lib BUILD_IN_SOURCE 1 BUILD_COMMAND make @@ -343,7 +397,8 @@ endif () message("----------------------------------------------------") message("TARS_MYSQL: ${TARS_MYSQL}") +message("TARS_GZIP: ${TARS_GZIP}") message("TARS_HTTP2: ${TARS_HTTP2}") message("TARS_SSL: ${TARS_SSL}") message("TARS_PROTOBUF: ${TARS_PROTOBUF}") -message("TARS_GPERF: ${TARS_GPERF}") +#message("TARS_GPERF: ${TARS_GPERF}") diff --git a/cross-compiler.cmake b/cross-compiler.cmake new file mode 100644 index 00000000..7ea74155 --- /dev/null +++ b/cross-compiler.cmake @@ -0,0 +1,16 @@ +# configure cross compilation +set(CMAKE_SYSTEM_NAME Linux) +set(CMAKE_SYSTEM_PROCESSOR aarch) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb") +SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O2 -Wall") + +# you need to set the path to the cross compiler +set(TOOLCHAIN_DIR /root/boat/gcc-linaro-5.4.1-2017.01-x86_64_arm-linux-gnueabi) +set(CMAKE_C_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gnueabi-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_DIR}/bin/arm-linux-gnueabi-g++) + diff --git a/examples/PushCallbackDemo/Server/HelloImp.cpp b/examples/PushCallbackDemo/Server/HelloImp.cpp index d72dc8fd..7d357820 100644 --- a/examples/PushCallbackDemo/Server/HelloImp.cpp +++ b/examples/PushCallbackDemo/Server/HelloImp.cpp @@ -37,6 +37,7 @@ void HelloImp::destroy() int HelloImp::doClose(tars::TarsCurrentPtr current) { g_app._pushThread.delCurrent(current); + return 0; } int HelloImp::registerPush(tars::TarsCurrentPtr current) diff --git a/servant/libservant/AdapterProxy.cpp b/servant/libservant/AdapterProxy.cpp index 3b54b532..13792c17 100755 --- a/servant/libservant/AdapterProxy.cpp +++ b/servant/libservant/AdapterProxy.cpp @@ -152,7 +152,7 @@ void AdapterProxy::onCloseCallback(TC_Transceiver* trans, TC_Transceiver::CloseR { if(_objectProxy->getRootServantProxy()->tars_get_push_callback()) { - _objectProxy->getRootServantProxy()->tars_get_push_callback()->onClose(); + _objectProxy->getRootServantProxy()->tars_get_push_callback()->onClose(trans->getConnectEndpoint()); } int millisecond =_objectProxy->reconnect(); @@ -166,7 +166,7 @@ void AdapterProxy::onCloseCallback(TC_Transceiver* trans, TC_Transceiver::CloseR return; } - _objectProxy->getCommunicatorEpoll()->reConnect(TNOWMS + millisecond, trans); + _objectProxy->getCommunicatorEpoll()->reConnect(TNOWMS + millisecond, this); TLOGERROR("[trans close:" << _objectProxy->name() << "," << trans->getConnectEndpoint().toString() << ", reconnect:" << millisecond << " ms]" << endl); } @@ -175,9 +175,11 @@ void AdapterProxy::onConnectCallback(TC_Transceiver* trans) // LOG_CONSOLE_DEBUG << "fd:" << trans->fd() << ", " << trans << endl; addConnExc(false); - if(_objectProxy->getRootServantProxy()->tars_get_push_callback()) + if(auto cb = _objectProxy->getRootServantProxy()->tars_get_push_callback()) { - _objectProxy->getRootServantProxy()->tars_get_push_callback()->onConnect(trans->getConnectEndpoint()); + cb->onConnect(trans->getConnectEndpoint()); + // 回调socket句柄, 外部可获取本地socket相关信息, 如:合规留痕需要 + cb->onConnect(trans->getConnectEndpoint(), trans->fd()); } _objectProxy->onConnect(this); @@ -192,6 +194,7 @@ void AdapterProxy::onRequestCallback(TC_Transceiver* trans) TC_NetWorkBuffer::PACKET_TYPE AdapterProxy::onParserCallback(TC_NetWorkBuffer& buff, TC_Transceiver* trans) { // LOG_CONSOLE_DEBUG << "fd:" << trans->fd() << ", " << trans<< endl; + try { shared_ptr rsp = std::make_shared(); @@ -762,11 +765,17 @@ void AdapterProxy::onSetInactive() _trans->close(); } -//屏蔽结点 +void AdapterProxy::onClose() +{ + _trans->close(); +} + +//屏蔽节点 void AdapterProxy::setInactive() { onSetInactive(); + //通知根servant下面的所有servant都屏蔽 _objectProxy->getRootServantProxy()->onSetInactive(_ep); TLOGTARS("[AdapterProxy::setInactive, " << _objectProxy->name() << ", " << _trans->getConnectionString() << ", inactive]" << endl); @@ -835,11 +844,11 @@ void AdapterProxy::finishInvoke_parallel(shared_ptr & rsp) } else { - //这里的队列中的发送链表中的数据可能已经在timeout的时候删除了,因此可能会core,在erase中要加判断 + //这里的队列中的发送链表中的数据可能已经在timeout的时候删除了,因此可能会core,在erase中要加判断 //获取请求信息 bool retErase = _timeoutQueue->erase(rsp->iRequestId, msg); - //找不到此id信息 + //找不到此id信息 if (!retErase) { if (_timeoutLogFlag) @@ -877,7 +886,6 @@ void AdapterProxy::finishInvoke(shared_ptr & rsp) void AdapterProxy::finishInvoke(ReqMessage * msg) { // assert(msg->eStatus != ReqMessage::REQ_REQ); - TLOGTARS("[AdapterProxy::finishInvokeMsg " << _objectProxy->name() << ", " << _trans->getConnectionString() << " ,id:" << msg->response->iRequestId << "]" << endl); // #ifdef TARS_OPENTRACKING diff --git a/servant/libservant/Application.cpp b/servant/libservant/Application.cpp index 8d344efd..e9ad500c 100644 --- a/servant/libservant/Application.cpp +++ b/servant/libservant/Application.cpp @@ -970,8 +970,6 @@ void Application::outClient(ostream &os) 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("sample-rate") << _communicator->getProperty("sample-rate") << endl; -// os << TC_Common::outfill("max-sample-count") << _communicator->getProperty("max-sample-count") << 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; @@ -1020,6 +1018,13 @@ void Application::onAccept(TC_EpollServer::Connection* cPtr) } } +TC_EpollServer::BindAdapterPtr Application::getBindAdapter(const string &obj) +{ + string adapter = this->_servantHelper->getServantAdapter(obj); + + return _epollServer->getBindAdapter(adapter); +} + //void Application::addServantOnClose(const string& servant, const TC_EpollServer::close_functor& cf) //{ // string adapterName = _servantHelper->getServantAdapter(servant); diff --git a/servant/libservant/Communicator.cpp b/servant/libservant/Communicator.cpp index 0154f24f..822c5079 100644 --- a/servant/libservant/Communicator.cpp +++ b/servant/libservant/Communicator.cpp @@ -58,6 +58,9 @@ Communicator::Communicator() WSAStartup(MAKEWORD(2, 2), &wsadata); #endif +#if TARS_SSL + _ctx = TC_OpenSSL::newCtx("", "", "", false, ""); +#endif } Communicator::Communicator(TC_Config& conf, const string& domain/* = CONFIG_ROOT_PATH*/) @@ -70,6 +73,11 @@ Communicator::Communicator(TC_Config& conf, const string& domain/* = CONFIG_ROOT // #endif { setProperty(conf, domain); + +#if TARS_SSL + _ctx = TC_OpenSSL::newCtx("", "", "", false, ""); +#endif + } Communicator::~Communicator() @@ -153,9 +161,9 @@ shared_ptr Communicator::newClientSSL(const string & objName) return TC_OpenSSL::newSSL(it->second); } - if(!_ctx) { - _ctx = TC_OpenSSL::newCtx("", "", "", false, ""); - } +// if(!_ctx) { +// _ctx = TC_OpenSSL::newCtx("", "", "", false, ""); +// } return TC_OpenSSL::newSSL(_ctx); #else diff --git a/servant/libservant/CommunicatorEpoll.cpp b/servant/libservant/CommunicatorEpoll.cpp index 1635a41f..bf9eed71 100755 --- a/servant/libservant/CommunicatorEpoll.cpp +++ b/servant/libservant/CommunicatorEpoll.cpp @@ -203,12 +203,28 @@ void CommunicatorEpoll::terminate() notifyTerminate(); } -void CommunicatorEpoll::notifyUpdateEndpoints(ServantProxy *servantProxy, const set & active,const set & inactive) +//void CommunicatorEpoll::notifyUpdateEndpoints(ServantProxy *servantProxy, const set & active,const set & inactive) +//{ +// CommunicatorEpoll *ce = this; +// +// _epoller->asyncCallback([=]() +// { servantProxy->onNotifyEndpoints(ce, active, inactive); }); +//} + +void CommunicatorEpoll::notifyClose(ServantProxy *servantProxy) { CommunicatorEpoll *ce = this; _epoller->asyncCallback([=]() - { servantProxy->onNotifyEndpoints(ce, active, inactive); }); + { servantProxy->onClose(ce); }); +} + +void CommunicatorEpoll::notifySetInactive(ServantProxy *servantProxy, const EndpointInfo &ep) +{ + CommunicatorEpoll *ce = this; + + _epoller->asyncCallback([=]() + { servantProxy->onSetInactive(ce, ep); }); } int CommunicatorEpoll::loadObjectLocator() @@ -366,7 +382,7 @@ bool CommunicatorEpoll::handleInputImp(const shared_ptr & catch(const std::exception& e) { // LOG_CONSOLE_DEBUG << "[CommunicatorEpoll::handleInputImp] error:" << e.what() << endl; - TLOGTARS("[CommunicatorEpoll::handleInputImp] error:" << e.what() << endl); +// TLOGTARS("[CommunicatorEpoll::handleInputImp] error:" << e.what() << endl); adapterProxy->addConnExc(true); return false; } @@ -391,7 +407,7 @@ bool CommunicatorEpoll::handleOutputImp(const shared_ptr { // LOG_CONSOLE_DEBUG << "[CommunicatorEpoll::handleOutputImp] error:" << e.what() << endl; - TLOGTARS("[CommunicatorEpoll::handleOutputImp] error:" << e.what() << endl); +// TLOGTARS("[CommunicatorEpoll::handleOutputImp] error:" << e.what() << endl); adapterProxy->addConnExc(true); return false; } @@ -506,7 +522,7 @@ void CommunicatorEpoll::doReconnect() int64_t iNow = TNOWMS; - set does; + set does; while(!_reconnect.empty()) { auto it = _reconnect.begin(); @@ -517,14 +533,15 @@ void CommunicatorEpoll::doReconnect() } //一次循环同一个节点只尝试一次重试,以避免多次触发close,导致重连的间隔无效 - if (does.find(it->second) != does.end()) + //如果已经取消重练了, 则不再重连 + if (does.find(it->second) != does.end() || it->second->getObjProxy()->reconnect() > 0) { _reconnect.erase(it++); } else { does.insert(it->second); - it->second->connect(); + it->second->trans()->connect(); _reconnect.erase(it++); } } diff --git a/servant/libservant/Current.cpp b/servant/libservant/Current.cpp index e7b835b8..7ca9f15d 100644 --- a/servant/libservant/Current.cpp +++ b/servant/libservant/Current.cpp @@ -172,9 +172,9 @@ void Current::initialize(const shared_ptr &data) _data = data; - Application *application = (Application*)this->_servantHandle->getApplication(); +// Application *application = (Application*)this->_servantHandle->getApplication(); - _request.sServantName = application->getServantHelper()->getAdapterServant(_data->adapter()->getName()); +// _request.sServantName = application->getServantHelper()->getAdapterServant(_data->adapter()->getName()); _isTars = _data->adapter()->isTarsProtocol(); @@ -182,15 +182,21 @@ void Current::initialize(const shared_ptr &data) { initialize(_data->buffer()); } + else + { + _request.sServantName = this->_servantHandle->getServant()->getName(); + } } void Current::initializeClose(const shared_ptr &data) { _data = data; - Application *application = (Application*)this->_servantHandle->getApplication(); +// Application *application = (Application*)this->_servantHandle->getApplication(); + + _request.sServantName = this->_servantHandle->getServant()->getName(); - _request.sServantName = application->getServantHelper()->getAdapterServant(_data->adapter()->getName()); +// _request.sServantName = application->getServantHelper()->getAdapterServant(_data->adapter()->getName()); } void Current::initialize(const vector& sRecvBuffer) diff --git a/servant/libservant/EndpointManager.cpp b/servant/libservant/EndpointManager.cpp index 96a50ef7..bbb3fc84 100644 --- a/servant/libservant/EndpointManager.cpp +++ b/servant/libservant/EndpointManager.cpp @@ -148,12 +148,15 @@ bool QueryEpBase::init(const string & sObjName, const string& setName, bool root _locator = _communicator->getProperty("locator"); TLOGTARS("QueryEpBase::init sObjName:" << sObjName << ", sLocator:" << _locator << ", setName:" << setName << ", rootServant: " << rootServant << endl); -// LOG_CONSOLE_DEBUG << "QueryEpBase::init sObjName:" << sObjName << ", sLocator:" << _locator << ", setName:" << setName << ", rootServant: " << rootServant << endl; _invokeSetId = setName; _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; @@ -182,6 +185,13 @@ void QueryEpBase::setObjName(const string & sObjName) _direct = true; + //如果就是主控, 则认为是非direct + size_t pos = _locator.find_first_not_of('@'); + if(pos != string::npos && _objName == _locator.substr(0, pos)) + { + _direct = false; + } + _valid = true; } else @@ -347,7 +357,7 @@ void QueryEpBase::refreshReg(GetEndpointType type, const string & sName) TLOGTARS("[QueryEpBase::refresh," << _objName << "]" < &vRouterCache) +AdapterProxy* EndpointManager::getHashProxyForWeight(int64_t hashCode, bool bStatic, vector &vRouterCache) { if(_vRegProxys.empty()) { @@ -954,7 +964,7 @@ AdapterProxy* EndpointManager::getHashProxyForWeight(uint32_t hashCode, bool bSt if(vRouterCache.size() > 0) { - size_t hash = hashCode % vRouterCache.size(); + size_t hash = ((int64_t)hashCode) % vRouterCache.size(); //这里做判断的原因是:32位系统下,如果hashCode为负值,hash经过上面的计算会是一个超大值,导致越界 if(hash >= vRouterCache.size()) @@ -989,7 +999,13 @@ AdapterProxy* EndpointManager::getHashProxyForWeight(uint32_t hashCode, bool bSt do { - hash = hashCode % thisHash.size(); + hash = ((int64_t)hashCode) % thisHash.size(); + + //这里做判断的原因是:32位系统下,如果hashCode为负值,hash经过上面的计算会是一个超大值,导致越界 + if(hash >= thisHash.size()) + { + hash = hash % thisHash.size(); + } if (thisHash[hash]->checkActive(true)) { @@ -1006,7 +1022,13 @@ AdapterProxy* EndpointManager::getHashProxyForWeight(uint32_t hashCode, bool bSt if(conn.size() > 0) { - hash = hashCode % conn.size(); + hash = ((int64_t)hashCode) % conn.size(); + + //这里做判断的原因是:32位系统下,如果hashCode为负值,hash经过上面的计算会是一个超大值,导致越界 + if(hash >= conn.size()) + { + hash = hash % conn.size(); + } //都有问题, 随机选择一个没有connect超时或者链接异常的发送 AdapterProxy *adapterProxy = conn[hash]; @@ -1032,7 +1054,7 @@ AdapterProxy* EndpointManager::getHashProxyForWeight(uint32_t hashCode, bool bSt } -AdapterProxy* EndpointManager::getConHashProxyForWeight(uint32_t hashCode, bool bStatic) +AdapterProxy* EndpointManager::getConHashProxyForWeight(int64_t hashCode, bool bStatic) { if(_vRegProxys.empty()) { @@ -1361,7 +1383,7 @@ void EndpointManager::updateConHashProxyWeighted(bool bStatic, map= _vRegProxys.size()) + { + hash = hash % _vRegProxys.size(); + } //被hash到的节点在主控是active的才走在流程 if (_vRegProxys[hash]->isActiveInReg() && _vRegProxys[hash]->checkActive(true)) @@ -1394,7 +1422,13 @@ AdapterProxy* EndpointManager::getHashProxyForNormal(uint32_t hashCode) do { - hash = hashCode % thisHash.size(); + hash = ((int64_t)hashCode) % thisHash.size(); + + //这里做判断的原因是:32位系统下,如果hashCode为负值,hash经过上面的计算会是一个超大值,导致越界 + if(hash >= thisHash.size()) + { + hash = hash % thisHash.size(); + } if (thisHash[hash]->checkActive(true)) { @@ -1411,7 +1445,13 @@ AdapterProxy* EndpointManager::getHashProxyForNormal(uint32_t hashCode) if(conn.size() > 0) { - hash = hashCode % conn.size(); + hash = ((int64_t)hashCode) % conn.size(); + + //这里做判断的原因是:32位系统下,如果hashCode为负值,hash经过上面的计算会是一个超大值,导致越界 + if(hash >= conn.size()) + { + hash = hash % conn.size(); + } //都有问题, 随机选择一个没有connect超时或者链接异常的发送 AdapterProxy *adapterProxy = conn[hash]; @@ -1432,7 +1472,7 @@ AdapterProxy* EndpointManager::getHashProxyForNormal(uint32_t hashCode) } } -AdapterProxy* EndpointManager::getConHashProxyForNormal(uint32_t hashCode) +AdapterProxy* EndpointManager::getConHashProxyForNormal(int64_t hashCode) { if(_vRegProxys.empty()) { diff --git a/servant/libservant/ObjectProxy.cpp b/servant/libservant/ObjectProxy.cpp index 9ccf3315..a7735435 100755 --- a/servant/libservant/ObjectProxy.cpp +++ b/servant/libservant/ObjectProxy.cpp @@ -55,6 +55,7 @@ ObjectProxy::ObjectProxy(CommunicatorEpoll *pCommunicatorEpoll, ServantProxy *se } } + //#, hash模式, 创建多个连接的情况(http) pos = _name.find_first_of('#'); if(pos != string::npos) @@ -404,5 +405,22 @@ void ObjectProxy::onSetInactive(const EndpointInfo& ep) } } +void ObjectProxy::close() +{ + if(!_hasInitialize) + { + return; + } + assert(this->getCommunicatorEpoll()->getThreadId() == this_thread::get_id()); + + const vector & vAdapterProxy = _endpointManger->getAdapters(); + for(size_t iAdapter=0; iAdapter< vAdapterProxy.size();++iAdapter) + { + if(vAdapterProxy[iAdapter] != NULL) + { + vAdapterProxy[iAdapter]->onClose(); + } + } +} ////////////////////////////////////////////////////////////////////////////////// } diff --git a/servant/libservant/RemoteLogger.cpp b/servant/libservant/RemoteLogger.cpp index d8332fcc..c7c6f4d1 100644 --- a/servant/libservant/RemoteLogger.cpp +++ b/servant/libservant/RemoteLogger.cpp @@ -555,7 +555,7 @@ void TimeWriteT::writeError(const deque > &buffer) ///////////////////////////////////////////////////////////////////////////////////// -RemoteTimeLogger::RemoteTimeLogger() : _defaultLogger(NULL),_hasSufix(true),_hasAppNamePrefix(true),_concatStr("_"),_separ("|"),_hasSquareBracket(false),_local(true),_remote(true) +RemoteTimeLogger::RemoteTimeLogger() : _defaultLogger(NULL),_hasSufix(true),_hasAppNamePrefix(true),_concatStr("_"),_separ("|"),_hasSquareBracket(false),_local(true),_remote(true),_logStatReport(false) { } @@ -643,7 +643,7 @@ void RemoteTimeLogger::initTimeLogger(TimeLogger *pTimeLogger, const string &sFi //////////// PropertyReportPtr reportSuccPtr = NULL; PropertyReportPtr reportFailPtr = NULL; - if (_remote && _logStatReport) + if (_remote && _logStatReport && _comm) { string sKey = _app + "." + _server + "." + sFile; reportSuccPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_succ", PropertyReport::sum()); @@ -713,7 +713,7 @@ void RemoteTimeLogger::initTimeLogger(TimeLogger *pTimeLogger,const string &sApp PropertyReportPtr reportSuccPtr = NULL; PropertyReportPtr reportFailPtr = NULL; - if (_remote && _logStatReport) + if (_remote && _logStatReport && _comm) { string sKey = _app + "." + _server + "." + sFile; reportSuccPtr = _comm->getStatReport()->createPropertyReport(sKey + "_log_send_succ", PropertyReport::sum()); diff --git a/servant/libservant/ServantHandle.cpp b/servant/libservant/ServantHandle.cpp index 5d582892..e0e5ff87 100644 --- a/servant/libservant/ServantHandle.cpp +++ b/servant/libservant/ServantHandle.cpp @@ -41,13 +41,14 @@ ServantHandle::ServantHandle(Application *application) ServantHandle::~ServantHandle() { - auto it = _servants.begin(); +// auto it = _servants.begin(); - while(it != _servants.end()) +// while(it != _servants.end()) +// if(_servant) { try { - it->second->destroy(); + _servant->destroy(); } catch(exception &ex) { @@ -57,7 +58,7 @@ ServantHandle::~ServantHandle() { TLOGERROR("[ServantHandle::destroy unknown exception error]" << endl); } - ++it; +// ++it; } } @@ -65,25 +66,26 @@ void ServantHandle::handleAsyncResponse() { ReqMessagePtr resp; - auto it = _servants.begin(); - - while (it != _servants.end()) +// auto it = _servants.begin(); +// +// while (it != _servants.end()) +// if(_servant) { - while (it->second->getResponseQueue().pop_front(resp)) + while (_servant->getResponseQueue().pop_front(resp)) { try { if (resp->response->iRet == TARSSERVERSUCCESS) { - it->second->doResponse(resp); + _servant->doResponse(resp); } else if (resp->pObjectProxy == NULL) { - it->second->doResponseNoRequest(resp); + _servant->doResponseNoRequest(resp); } else { - it->second->doResponseException(resp); + _servant->doResponseException(resp); } } catch (exception& e) @@ -99,8 +101,8 @@ void ServantHandle::handleAsyncResponse() //业务处理附加的自有消息 try { - it->second->doCustomMessage(false); - it->second->doCustomMessage(); + _servant->doCustomMessage(false); + _servant->doCustomMessage(); } catch (exception& e) { @@ -111,19 +113,20 @@ void ServantHandle::handleAsyncResponse() TLOGERROR("[ServantHandle::doCustemMessage ex.]" << endl); } - ++it; +// ++it; } } void ServantHandle::handleCustomMessage(bool bExpectIdle) { - for (auto it = _servants.begin(); it != _servants.end(); it++) +// for (auto it = _servants.begin(); it != _servants.end(); it++) +// if(_servant) { //业务处理附加的自有消息 try { - it->second->doCustomMessage(bExpectIdle); - it->second->doCustomMessage(); + _servant->doCustomMessage(bExpectIdle); + _servant->doCustomMessage(); } catch (exception& e) { @@ -138,15 +141,16 @@ void ServantHandle::handleCustomMessage(bool bExpectIdle) bool ServantHandle::allFilterIsEmpty() { - auto it = _servants.begin(); +// auto it = _servants.begin(); - while (it != _servants.end()) +// while (it != _servants.end()) +// if(_servant) { - if (!it->second->getResponseQueue().empty()) + if (!_servant->getResponseQueue().empty()) { return false; } - ++it; +// ++it; } return true; } @@ -158,13 +162,16 @@ void ServantHandle::initialize() ServantProxyThreadData::getData()->_sched = TC_CoroutineScheduler::scheduler(); } - ServantPtr servant = _application->getServantHelper()->create(_bindAdapter->getName()); + _servant = _application->getServantHelper()->create(_bindAdapter->getName()); - if (servant) - { - _servants[servant->getName()] = servant; - } - else +// ServantPtr servant = _application->getServantHelper()->create(_bindAdapter->getName()); + +// if (servant) +// { +// _servants[servant->getName()] = servant; +// } +// else + if(!_servant) { TLOGERROR("[ServantHandle initialize createServant ret null, for adapter `" +_bindAdapter->getName() + "`]" << endl); cerr << "ServantHandle initialize createServant ret null, for adapter `" +_bindAdapter->getName() + "`]" << endl; @@ -176,28 +183,28 @@ void ServantHandle::initialize() 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); - } +// 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()) - { +// while(it != _servants.end()) +// { try { - it->second->setHandle(this); + _servant->setHandle(this); - it->second->initialize(); + _servant->initialize(); - TLOGTARS("[" << it->second->getName() << " initialize]" << endl); + TLOGTARS("[" << _servant->getName() << " initialize]" << endl); } catch(exception &ex) { @@ -219,8 +226,8 @@ void ServantHandle::initialize() exit(-1); } - ++it; - } +// ++it; +// } } void ServantHandle::heartbeat() @@ -258,7 +265,7 @@ CurrentPtr ServantHandle::createCurrent(const shared_ptr &d CurrentPtr current = createCloseCurrent(data); - auto sit = _servants.find(current->getServantName()); - - if (sit == _servants.end()) - { - TLOGERROR("[TARS]ServantHandle::handleClose,adapter:" << data->adapter()->getName() << ",peer:" << data->ip() << ":" << data->port() << ", " << current->getServantName() << " not found" << endl); - - return; - } +// auto sit = _servants.find(current->getServantName()); - try - { - //业务逻辑处理 - sit->second->doClose(current); - } - catch (exception& ex) - { - TLOGERROR("[TARS]ServantHandle::handleClose " << ex.what() << 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) + { + try + { + //业务逻辑处理 + _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) @@ -610,9 +620,7 @@ void ServantHandle::handleTarsProtocol(const CurrentPtr ¤t) } // processSample(current); - auto sit = _servants.find(current->getServantName()); - - if (sit == _servants.end()) + if(_servant->getName() != current->getServantName()) { current->sendResponse(TARSSERVERNOSERVANTERR); // #ifdef TARS_OPENTRACKING @@ -630,7 +638,7 @@ void ServantHandle::handleTarsProtocol(const CurrentPtr ¤t) try { //业务逻辑处理 - ret = sit->second->dispatch(current, response.sBuffer); + ret = _servant->dispatch(current, response.sBuffer); } catch(TarsDecodeException &ex) { @@ -667,7 +675,7 @@ void ServantHandle::handleTarsProtocol(const CurrentPtr ¤t) if(ret == TARSSERVERNOFUNCERR) { - ret = sit->second->doNoFunc(current); + ret = _servant->doNoFunc(current); } //单向调用或者业务不需要同步返回 @@ -687,16 +695,15 @@ void ServantHandle::handleNoTarsProtocol(const TarsCurrentPtr ¤t) << current->getPort() << "|" << current->getServantName() << "]" << endl); - auto sit = _servants.find(current->getServantName()); - - assert(sit != _servants.end()); +// auto sit = _servants.find(current->getServantName()); +// assert(sit != _servants.end()); vector buffer; try { //业务逻辑处理 - sit->second->dispatch(current, buffer); + _servant->dispatch(current, buffer); } catch(exception &ex) { diff --git a/servant/libservant/ServantHelper.cpp b/servant/libservant/ServantHelper.cpp index fad67c0e..eea8bc9a 100644 --- a/servant/libservant/ServantHelper.cpp +++ b/servant/libservant/ServantHelper.cpp @@ -48,7 +48,7 @@ void ServantHelperManager::setAdapterServant(const string &sAdapter, const strin bool ServantHelperManager::setDyeing(const string & sDyeingKey, const string & sDyeingServant, const string & sDyeingInterface) { - TC_LockT lock(_mutex); + TC_LockT lock(_mutex); _dyeingKey = sDyeingKey; _dyeingServant = sDyeingServant; @@ -61,7 +61,7 @@ bool ServantHelperManager::setDyeing(const string & sDyeingKey, const string & s bool ServantHelperManager::isDyeingReq(const string & sKey, const string & sServant, const string & sInterface) const { - TC_LockT lock(_mutex); + TC_LockT lock(_mutex); return ((_dyeingKey == sKey) && (_dyeingServant == sServant) && (_dyeingInterface == "" || _dyeingInterface == sInterface) ); diff --git a/servant/libservant/ServantProxy.cpp b/servant/libservant/ServantProxy.cpp index 9eb81d55..d114209c 100644 --- a/servant/libservant/ServantProxy.cpp +++ b/servant/libservant/ServantProxy.cpp @@ -31,7 +31,7 @@ namespace tars shared_ptr ServantProxyThreadData::g_immortal; thread_local shared_ptr ServantProxyThreadData::g_sp; -unsigned int ServantProxyThreadData::_traceParamMaxLen = 1; // 默认1K +unsigned int _traceParamMaxLen = 1; // 默认1K /////////////////////////////////////////////////////////////// SeqManager::SeqManager(uint16_t iNum) @@ -109,6 +109,20 @@ void SeqManager::del(uint16_t iSeq) /////////////////////////////////////////////////////////////// +void ServantProxyThreadData::setTraceParamMaxLen(unsigned int len) +{ + // 最最大保护,不超过10M + if (len < 1024 * 10) + { + _traceParamMaxLen = len; + } +} + +unsigned int ServantProxyThreadData::getTraceParamMaxLen() +{ + return _traceParamMaxLen; +} + ServantProxyThreadData::Immortal::Immortal() { _pSeq.reset(new SeqManager(MAX_CLIENT_NOTIFYEVENT_NUM)); @@ -165,8 +179,6 @@ ServantProxyThreadData::~ServantProxyThreadData() // LOG_CONSOLE_DEBUG << endl; try { -// TC_LockT lock(_mutex); - //先释放公有的网络通信器的信息 for(auto it = _communicatorEpollInfo.begin(); it != _communicatorEpollInfo.end(); ++it) { @@ -306,6 +318,18 @@ int ServantProxyCallback::dispatch(ReqMessagePtr msg) return onDispatch(msg); } +const map & ServantProxyCallback::getResponseContext() const +{ + CallbackThreadData * pCbtd = CallbackThreadData::getData(); + assert(pCbtd != NULL); + + if(!pCbtd->getContextValid()) + { + throw TC_Exception("cann't get response context"); + } + return pCbtd->getResponseContext(); +} + /////////////////////////////////////////////////////////////////////////////////////////// int HttpServantProxyCallback::onDispatch(ReqMessagePtr msg) @@ -686,7 +710,6 @@ void ServantProxy::tars_ping() tars_invoke(TARSNORMAL, "tars_ping", os, m, s); } - void ServantProxy::tars_async_ping() { map m; @@ -697,7 +720,7 @@ void ServantProxy::tars_async_ping() tars_invoke_async(TARSONEWAY, "tars_ping", os, m, s, NULL); } -ServantProxy* ServantProxy::tars_hash(uint32_t key) +ServantProxy* ServantProxy::tars_hash(size_t key) { ServantProxyThreadData *pSptd = ServantProxyThreadData::getData(); @@ -709,15 +732,7 @@ ServantProxy* ServantProxy::tars_hash(uint32_t key) return this; } -//ServantProxy* ServantProxy::tars_direct() -//{ -// ServantProxyThreadData *pSptd = ServantProxyThreadData::getData(); -// -// pSptd->_direct = true; -// return this; -//} - -ServantProxy* ServantProxy::tars_consistent_hash(uint32_t key) +ServantProxy* ServantProxy::tars_consistent_hash(size_t key) { ServantProxyThreadData *pSptd = ServantProxyThreadData::getData(); @@ -756,7 +771,6 @@ ServantProxy* ServantProxy::tars_set_timeout(int msecond) ServantProxyThreadData *pSptd = ServantProxyThreadData::getData(); assert(pSptd != NULL); -// pSptd->_hasTimeout = true; pSptd->_data._timeout = msecond; return this; @@ -890,6 +904,10 @@ void ServantProxy::invoke(ReqMessage *msg, bool bCoroAsync) bool bEmpty = false; bool bSync = (msg->eType == ReqMessage::SYNC_CALL); + //赋值出来, 避免极端情况(异步请求都处理完了, msg已经释放, 才进入到后面的判断, 目前发现在麒麟OS上会出现) + auto sched = msg->sched; + auto pObjectProxy = msg->pObjectProxy; + if (!pReqQ->push_back(msg, bEmpty)) { TLOGERROR("[ServantProxy::invoke msgQueue push_back error thread seq:" << pSptd->_reqQNo << "]" << endl); @@ -900,16 +918,14 @@ void ServantProxy::invoke(ReqMessage *msg, bool bCoroAsync) throw TarsClientQueueException("client queue full"); } - if (msg->sched) + if (sched) { -// LOG_CONSOLE_DEBUG << "in sched handle: " << this << ", " << msg->request.sServantName << endl; - //协程中, 直接发包了 - msg->pObjectProxy->getCommunicatorEpoll()->handle(pSptd->_reqQNo); + pObjectProxy->getCommunicatorEpoll()->handle(pSptd->_reqQNo); } else { - msg->pObjectProxy->getCommunicatorEpoll()->notify(pSptd->_reqQNo); + pObjectProxy->getCommunicatorEpoll()->notify(pSptd->_reqQNo); } if (bSync) @@ -1224,7 +1240,7 @@ ServantPrx ServantProxy::getServantPrx(ReqMessage *msg) void ServantProxy::travelObjectProxys(ServantProxy *prx, function f) { - vector objectProxys; +// vector objectProxys; size_t num = _communicator->getCommunicatorEpollNum(); @@ -1278,27 +1294,71 @@ void ServantProxy::tars_update_endpoints(const set &active, const onNotifyEndpoints(NULL, active, inactive); } +//在网络线程中回调 void ServantProxy::onNotifyEndpoints(CommunicatorEpoll *communicatorEpoll, const set &active, const set &inactive) { - //更新子servant proxy的地址 - for (size_t i = 0; i < _servantList.size(); i++) - { - ServantProxy* prx = _servantList[i].get(); + //更新子servant proxy的地址 + for (size_t i = 0; i < _servantList.size(); i++) + { + ServantProxy* prx = _servantList[i].get(); - travelObjectProxys(prx, [&](ObjectProxy *op){ - if(op->getEndpointManager()) - { - op->getEndpointManager()->updateEndpointsOutter(active, inactive); - } - }); - } + travelObjectProxys(prx, [&](ObjectProxy *op){ + if(op->getEndpointManager()) + { + op->getEndpointManager()->updateEndpointsOutter(active, inactive); + } + }); + } + + travelObjectProxys(this, [&](ObjectProxy *op){ + if(op->getEndpointManager()) + { + op->getEndpointManager()->updateEndpointsOutter(active, inactive); + } + }); +} + +void ServantProxy::tars_close() +{ + tars_open_keepalive(false); + tars_reconnect(0); + + size_t num = _communicator->getCommunicatorEpollNum(); + + for (size_t i = 0; i < num; ++i) + { + auto ce = _communicator->getCommunicatorEpoll(i); + + ce->notifyClose(this); + } + + //协程通信器也需要 + _communicator->forEachSchedCommunicatorEpoll([&](const shared_ptr& ce) + { + ce->notifyClose(this); + }); - travelObjectProxys(this, [&](ObjectProxy *op){ - if(op->getEndpointManager()) - { - op->getEndpointManager()->updateEndpointsOutter(active, inactive); - } - }); +} + +//在网络线程中回调 +void ServantProxy::onClose(CommunicatorEpoll *communicatorEpoll) +{ + for (size_t i = 0; i < _servantList.size(); i++) + { + ServantProxy* prx = _servantList[i].get(); + + ObjectProxy *op = communicatorEpoll->servantToObjectProxy(prx); + if(op) + { + op->close(); + } + } + + ObjectProxy *op = communicatorEpoll->servantToObjectProxy(this); + if(op) + { + op->close(); + } } void ServantProxy::onSetInactive(const EndpointInfo &ep) @@ -1306,11 +1366,47 @@ void ServantProxy::onSetInactive(const EndpointInfo &ep) if (!_rootPrx) return; - for (size_t i = 0; i < _rootPrx->_servantList.size(); i++) + size_t num = _communicator->getCommunicatorEpollNum(); + + for (size_t i = 0; i < num; ++i) { - ServantPrx &prx = _rootPrx->_servantList[i]; + auto ce = _communicator->getCommunicatorEpoll(i); + + ce->notifySetInactive(this, ep); + } - prx->forEachObject([&](ObjectProxy *o) { o->onSetInactive(ep); }); + //协程通信器也需要 + _communicator->forEachSchedCommunicatorEpoll([&](const shared_ptr& ce) + { + ce->notifySetInactive(this, ep); + }); + +// for (size_t i = 0; i < _rootPrx->_servantList.size(); i++) +// { +// ServantPrx &prx = _rootPrx->_servantList[i]; +// +// prx->forEachObject([&](ObjectProxy *o) { o->onSetInactive(ep); }); +// } +} + +//在网络线程中回调 +void ServantProxy::onSetInactive(CommunicatorEpoll *communicatorEpoll, const EndpointInfo &ep) +{ + for (size_t i = 0; i < _servantList.size(); i++) + { + ServantProxy* prx = _servantList[i].get(); + + ObjectProxy *op = communicatorEpoll->servantToObjectProxy(prx); + if(op) + { + op->onSetInactive(ep); + } + } + + ObjectProxy *op = communicatorEpoll->servantToObjectProxy(this); + if(op) + { + op->onSetInactive(ep); } } @@ -1328,7 +1424,7 @@ int ServantProxy::servant_invoke(ReqMessage *msg, bool bCoroAsync) return 0; } -void ServantProxy::http_call(const string &funcName, shared_ptr &request, shared_ptr &response) +void ServantProxy::http_call(const string &funcName, const shared_ptr &request, shared_ptr &response) { if (_connectionSerial <= 0) { @@ -1372,7 +1468,7 @@ void ServantProxy::http_call(const string &funcName, shared_ptr msg = NULL; } -void ServantProxy::http_call_async(const string &funcName, shared_ptr &request, const HttpCallbackPtr &cb, bool bCoro) +void ServantProxy::http_call_async(const string &funcName, const shared_ptr &request, const HttpCallbackPtr &cb, bool bCoro) { if (_connectionSerial <= 0) { @@ -1413,7 +1509,7 @@ void ServantProxy::http_call_async(const string &funcName, shared_ptr &request, shared_ptr &response) +void ServantProxy::common_protocol_call(const string &funcName, const shared_ptr &request, shared_ptr &response) { if (_connectionSerial <= 0) { @@ -1454,7 +1550,7 @@ void ServantProxy::common_protocol_call(const string &funcName, shared_ptr &request, const ServantProxyCallbackPtr &cb, bool bCoro) +void ServantProxy::common_protocol_call_async(const string &funcName, const shared_ptr &request, const ServantProxyCallbackPtr &cb, bool bCoro) { if (_connectionSerial <= 0) { diff --git a/servant/makefile/makefile.tars b/servant/makefile/makefile.tars index 0e810097..cc9f26e9 100644 --- a/servant/makefile/makefile.tars +++ b/servant/makefile/makefile.tars @@ -7,7 +7,7 @@ TARS_PATH :=/usr/local/tars/cpp CC = gcc CXX = g++ -CFLAGS += -std=c++11 -g -O2 -Wno-deprecated -Wall +CFLAGS += -std=c++11 -g -O2 -Wno-deprecated -Wall -fsigned-char #------------------------------------------------------------------------------- diff --git a/servant/makefile/tars-tools.cmake b/servant/makefile/tars-tools.cmake index 26259331..9fad7b57 100755 --- a/servant/makefile/tars-tools.cmake +++ b/servant/makefile/tars-tools.cmake @@ -4,12 +4,12 @@ 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") - set(TARSMERGE "c:/tars/cpp/tools/tarsmerge") + 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") else() - set(TARS2CPP "/usr/local/tars/cpp/tools/tars2cpp") - set(TARSMERGE "/usr/local/tars/cpp/tools/tarsmerge") + 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") endif() @@ -54,8 +54,8 @@ set(TARS_TOKEN "" CACHE STRING "set web token") set(PLATFORM) IF (UNIX) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++11 -Wno-deprecated -fno-strict-aliasing -Wno-overloaded-virtual") + 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_DEBUG "$ENV{CXXFLAGS} -Wall -g") @@ -72,13 +72,25 @@ IF (UNIX) ELSEIF (WIN32) set(PLATFORM "window") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4101 /wd4244 /wd4996 /wd4091 /wd4503 /wd4819 /wd4200 /wd4800 /wd4267") - 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") + + SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO") + SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO") + SET (CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /SAFESEH:NO") + + #Release生成PDB + SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /OPT:ICF /OPT:REF /DEBUG") + 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") ELSE () MESSAGE(STATUS "================ ERROR: This platform is unsupported!!! ================") ENDIF (UNIX) +#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char") + set(TARS_RELEASE "${PROJECT_BINARY_DIR}/run-release.cmake") FILE(WRITE ${TARS_RELEASE} "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E echo release all)\n") @@ -465,6 +477,7 @@ endif() message("-------------------------------------------------------------------------------------") message("CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}") message("CMAKE_BINARY_DIR: ${CMAKE_BINARY_DIR}") +message("CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}") message("PROJECT_SOURCE_DIR: ${PROJECT_SOURCE_DIR}") message("CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}") message("PLATFORM: ${PLATFORM}") diff --git a/servant/protocol b/servant/protocol index c1b0f612..9b3921b1 160000 --- a/servant/protocol +++ b/servant/protocol @@ -1 +1 @@ -Subproject commit c1b0f6122921ee01f6660cdd6f2e4ae7d57f879e +Subproject commit 9b3921b1036a24ed175650160f793b9b94459ea8 diff --git a/servant/servant/AdapterProxy.h b/servant/servant/AdapterProxy.h index d6e4c644..f744be71 100644 --- a/servant/servant/AdapterProxy.h +++ b/servant/servant/AdapterProxy.h @@ -209,12 +209,16 @@ class AdapterProxy */ inline int getId() const { return _id; } - /** * 屏蔽结点 */ void onSetInactive(); + /** + * 关闭连接 + */ + void onClose(); + /** * get timeout queue * @return diff --git a/servant/servant/AppProtocol.h b/servant/servant/AppProtocol.h index aeee332a..3b6692c8 100644 --- a/servant/servant/AppProtocol.h +++ b/servant/servant/AppProtocol.h @@ -35,7 +35,7 @@ namespace tars class TC_Transceiver; #define TARS_NET_MIN_PACKAGE_SIZE 5 -#define TARS_NET_MAX_PACKAGE_SIZE 1024*1024*10 +#define TARS_NET_MAX_PACKAGE_SIZE 1024*1024*100 template T net2host(T len) @@ -125,8 +125,6 @@ class AppProtocol } }; -//typedef std::function(RequestPacket&, TC_Transceiver *)> request_protocol; - typedef std::function(RequestPacket&, TC_Transceiver*)> request_protocol; typedef std::function response_protocol; @@ -286,7 +284,6 @@ class ProxyProtocol static TC_NetWorkBuffer::PACKET_TYPE jsonResponseLen(TC_NetWorkBuffer &in, ResponsePacket& rsp, uint32_t iMinLength, uint32_t iMaxLength); -public: /** * tars请求包 * @param request diff --git a/servant/servant/Application.h b/servant/servant/Application.h index 91588aa7..53fcd7d4 100644 --- a/servant/servant/Application.h +++ b/servant/servant/Application.h @@ -211,6 +211,11 @@ class Application: public BaseNotify * @return TC_EpollServerPtr& */ TC_EpollServerPtr &getEpollServer() { return _epollServer; } + + /** + * 获取服务server对象 + * @return + */ const TC_EpollServerPtr &getEpollServer() const { return _epollServer; } /** @@ -273,7 +278,7 @@ class Application: public BaseNotify * get notify observer * @return */ - shared_ptr &getNotifyObserver() { return _notifyObserver; } + const shared_ptr &getNotifyObserver() { return _notifyObserver; } /** * 非tars协议server,设置Servant的协议解析器 @@ -289,6 +294,13 @@ class Application: public BaseNotify */ void addAcceptCallback(const TC_EpollServer::accept_callback_functor& cb); + /** + * 根据obj名称获取到BindAdpaterPtr + * @param obj + * @return 如果获取不到返回NULL + */ + TC_EpollServer::BindAdapterPtr getBindAdapter(const string &obj); + protected: /** * 初始化, 只会进程调用一次 diff --git a/servant/servant/CommunicatorEpoll.h b/servant/servant/CommunicatorEpoll.h index 4d59a263..0d106b4f 100644 --- a/servant/servant/CommunicatorEpoll.h +++ b/servant/servant/CommunicatorEpoll.h @@ -163,11 +163,17 @@ class CommunicatorEpoll : public TC_Thread, public enable_shared_from_this & active,const set & inactive); + void notifySetInactive(ServantProxy *servantProxy, const EndpointInfo &ep); /** * 数据加入到异步线程队列里面 @@ -179,7 +185,7 @@ class CommunicatorEpoll : public TC_Thread, public enable_shared_from_this _reconnect; + unordered_map _reconnect; /** * 统计数据 diff --git a/servant/servant/EndpointManager.h b/servant/servant/EndpointManager.h index dace1625..b74f08c1 100644 --- a/servant/servant/EndpointManager.h +++ b/servant/servant/EndpointManager.h @@ -399,28 +399,28 @@ class EndpointManager : public QueryEpBase /* * 根据hash值选取一个结点 */ - AdapterProxy* getHashProxy(uint32_t hashCode, bool bConsistentHash = false); + AdapterProxy* getHashProxy(int64_t hashCode, bool bConsistentHash = false); /* * 根据hash值按取模方式,从正常节点中选取一个结点 */ - AdapterProxy* getHashProxyForNormal(uint32_t hashCode); + AdapterProxy* getHashProxyForNormal(int64_t hashCode); /* * 根据hash值按一致性hash方式,从正常节点中选取一个结点 */ - AdapterProxy* getConHashProxyForNormal(uint32_t hashCode); + AdapterProxy* getConHashProxyForNormal(int64_t hashCode); /* * 根据hash值按取模方式,从静态权重节点中选取一个结点 */ - AdapterProxy* getHashProxyForWeight(uint32_t hashCode, bool bStatic, vector &vRouterCache); + AdapterProxy* getHashProxyForWeight(int64_t hashCode, bool bStatic, vector &vRouterCache); /* * 根据hash值按一致性hash方式,从静态权重节点中选取一个结点 */ - AdapterProxy* getConHashProxyForWeight(uint32_t hashCode, bool bStatic); + AdapterProxy* getConHashProxyForWeight(int64_t hashCode, bool bStatic); /* * 判断静态权重节点是否有变化 diff --git a/servant/servant/Message.h b/servant/servant/Message.h index f36f0735..80b81c7f 100644 --- a/servant/servant/Message.h +++ b/servant/servant/Message.h @@ -52,7 +52,7 @@ struct CheckTimeoutInfo , checkTimeoutInterval(5) , frequenceFailInvoke(3) , minFrequenceFailTime(2) - , radio(0.3) + , radio(0.3f) , tryTimeInterval(10) , maxConnectExc(1) { @@ -106,7 +106,7 @@ struct ThreadPrivateData */ bool _hash = false; //是否普通取模hash bool _conHash = false; //是否一致性hash - uint32_t _hashCode = 0; //hash值 + int64_t _hashCode = -1; //hash值 /** * 染色信息 diff --git a/servant/servant/ObjectProxy.h b/servant/servant/ObjectProxy.h index da2cdf49..d6f81a6e 100644 --- a/servant/servant/ObjectProxy.h +++ b/servant/servant/ObjectProxy.h @@ -149,7 +149,7 @@ class ObjectProxy : public TC_HandleBase, public TC_ThreadMutex * reconnect * @return millisecond */ - inline int reconnect() { return _reConnectSecond; } + inline int64_t reconnect() { return _reConnectSecond; } /** * reconnect @@ -206,6 +206,10 @@ class ObjectProxy : public TC_HandleBase, public TC_ThreadMutex */ void onSetInactive(const EndpointInfo& ep); + /** + * 关闭所有网络连接 + */ + void close(); protected: /** @@ -259,7 +263,7 @@ class ObjectProxy : public TC_HandleBase, public TC_ThreadMutex /** * reconnect, 0: not reconnect, millisecond */ - int _reConnectSecond = 0; + int64_t _reConnectSecond = 0; bool _onlyActiveInReg = false; diff --git a/servant/servant/Servant.h b/servant/servant/Servant.h index c75ef49c..1c4367a0 100644 --- a/servant/servant/Servant.h +++ b/servant/servant/Servant.h @@ -29,6 +29,7 @@ namespace tars { class Application; + //////////////////////////////////////////////////////////////////// /** * 每个对象的基类 diff --git a/servant/servant/ServantHandle.h b/servant/servant/ServantHandle.h index 2e4f8f48..9a5e8c95 100644 --- a/servant/servant/ServantHandle.h +++ b/servant/servant/ServantHandle.h @@ -66,6 +66,11 @@ class ServantHandle : public TC_EpollServer::Handle */ Application *getApplication() { return _application; } + /** + * 获取实际的servant + * @return + */ + ServantPtr getServant() { return _servant; } protected: /** * 线程初始化 @@ -200,7 +205,7 @@ class ServantHandle : public TC_EpollServer::Handle /** * 处理对象 */ - unordered_map _servants; + ServantPtr _servant; // #ifdef TARS_OPENTRACKING diff --git a/servant/servant/ServantHelper.h b/servant/servant/ServantHelper.h index 82f66ac8..cd12b235 100644 --- a/servant/servant/ServantHelper.h +++ b/servant/servant/ServantHelper.h @@ -212,7 +212,7 @@ class SVT_DLL_API ServantHelperManager// : public TC_Singleton g_sp; - static unsigned int _traceParamMaxLen; + static thread_local shared_ptr g_sp; + /** * global Immortal ptr, 避免Immortal提前被释放掉 @@ -483,18 +483,10 @@ class ServantProxyThreadData : public std::enable_shared_from_this(flags); return TraceContext::needParam(es, type, len, maxLen); } - static void setTraceParamMaxLen(unsigned int len) - { - // 最最大保护,不超过10M - if (len < 1024 * 10) - { - _traceParamMaxLen = len; - } - } - static unsigned int getTraceParamMaxLen() - { - return _traceParamMaxLen; - } + static void setTraceParamMaxLen(unsigned int len); + + static unsigned int getTraceParamMaxLen(); + ////////////////////////////////////////////////////////////////////////////////////调用链追踪 end///// }; @@ -646,6 +638,12 @@ class ServantProxyCallback : virtual public TC_HandleBase return _bNetThreadProcess; } + /** + * + * @return + */ + virtual const map & getResponseContext() const; + public: /** * dispatch, call onDispatch @@ -669,9 +667,11 @@ class ServantProxyCallback : virtual public TC_HandleBase virtual void onClose(const TC_Endpoint& ep) {onClose();}; /** - * 连接已建立(push callback 才有效) + * 连接已建立(push callback 才有效), fd为socket句柄 */ - virtual void onConnect(const TC_Endpoint& ep) {}; + virtual void onConnect(const TC_Endpoint& ep) {} + + virtual void onConnect(const TC_Endpoint& ep, int fd) {} friend class AdapterProxy; protected: @@ -924,6 +924,14 @@ class ServantProxy : public TC_HandleBase, public TC_ThreadMutex */ void tars_connect_timeout(int conTimeout); + /** + * 主动关闭到服务器端的连接 + * 1 如果有keepalive也关闭 + * 2 如果后续发起请求, 会自动建立连接, 但是不再自动开启keepalive + * 3 如果设置了重连时间, 也取消重连 + */ + void tars_close(); + /** * set auto reconnect time * @return int, second @@ -1029,12 +1037,12 @@ class ServantProxy : public TC_HandleBase, public TC_ThreadMutex * @param key * @return ServantProxy* */ - virtual ServantProxy* tars_hash(uint32_t key); + virtual ServantProxy* tars_hash(size_t key); /** * 一致性hash方法 */ - virtual ServantProxy* tars_consistent_hash(uint32_t key); + virtual ServantProxy* tars_consistent_hash(size_t key); /** @@ -1134,13 +1142,13 @@ class ServantProxy : public TC_HandleBase, public TC_ThreadMutex * http协议同步远程调用 * @param funcName: 调用名称, 这里只是做统计用 */ - void http_call(const string &funcName, shared_ptr &request, shared_ptr &response); + void http_call(const string &funcName, const shared_ptr &request, shared_ptr &response); /** * http协议异步远程调用 * @param funcName: 调用名称, 这里只是做统计用 */ - void http_call_async(const string &funcName, shared_ptr &request, const HttpCallbackPtr &cb, bool bCoro = false); + void http_call_async(const string &funcName, const shared_ptr &request, const HttpCallbackPtr &cb, bool bCoro = false); /** * 通用协议同步调用(这种模式下, 一个连接上只能跑一个请求响应包, 和http模式keep-alive模式类似) @@ -1148,7 +1156,7 @@ class ServantProxy : public TC_HandleBase, public TC_ThreadMutex * @param request * @param response */ - void common_protocol_call(const string &funcName, shared_ptr &request, shared_ptr &response); + void common_protocol_call(const string &funcName, const shared_ptr &request, shared_ptr &response); /** * 通用协议异步调用(这种模式下, 一个连接上只能跑一个请求响应包, 和http模式keep-alive模式类似) @@ -1157,7 +1165,7 @@ class ServantProxy : public TC_HandleBase, public TC_ThreadMutex * @param cb * @param bCoro */ - void common_protocol_call_async(const string &funcName, shared_ptr &request, const ServantProxyCallbackPtr &cb, bool bCoro = false); + void common_protocol_call_async(const string &funcName, const shared_ptr &request, const ServantProxyCallbackPtr &cb, bool bCoro = false); /** * TARS协议同步方法调用 @@ -1286,15 +1294,26 @@ class ServantProxy : public TC_HandleBase, public TC_ThreadMutex void onNotifyEndpoints(CommunicatorEpoll *communicatorEpoll, const set & active,const set & inactive); /** - * 端口不活跃 + * 设置端口不活跃(内部AdapterProxy的回调) */ void onSetInactive(const EndpointInfo &ep); + + /** + * 设置端口不活跃, 每个通信器自己的回调 + */ + void onSetInactive(CommunicatorEpoll *communicatorEpoll, const EndpointInfo &ep); + /** * 检查是否需要设置cookie * @param req */ void checkCookie(RequestPacket &req); + /** + * 关闭连接 + * @param communicatorEpoll + */ + void onClose(CommunicatorEpoll *communicatorEpoll); private: friend class ObjectProxy; friend class AdapterProxy; diff --git a/tools/tars2cpp/tars2cpp.cpp b/tools/tars2cpp/tars2cpp.cpp index 6ccc707f..1859105b 100755 --- a/tools/tars2cpp/tars2cpp.cpp +++ b/tools/tars2cpp/tars2cpp.cpp @@ -3144,7 +3144,7 @@ string Tars2Cpp::generateH(const InterfacePtr &pPtr, const NamespacePtr &nPtr) c s << generateHAsync(vOperation[i], pPtr->getId()) << endl; } - s << TAB << pPtr->getId() << "Proxy* tars_hash(uint32_t key)" << endl; + s << TAB << pPtr->getId() << "Proxy* tars_hash(size_t key)" << endl; s << TAB << "{" << endl; INC_TAB; s << TAB << "return (" << pPtr->getId() + "Proxy*)ServantProxy::tars_hash(key);" << endl; @@ -3152,7 +3152,7 @@ string Tars2Cpp::generateH(const InterfacePtr &pPtr, const NamespacePtr &nPtr) c s << TAB << "}" << endl; s << endl; - s << TAB << pPtr->getId() << "Proxy* tars_consistent_hash(uint32_t key)" << endl; + s << TAB << pPtr->getId() << "Proxy* tars_consistent_hash(size_t key)" << endl; s << TAB << "{" << endl; INC_TAB; s << TAB << "return (" << pPtr->getId() + "Proxy*)ServantProxy::tars_consistent_hash(key);" << endl; diff --git a/tools/tarsgrammar/tars.tab.cpp b/tools/tarsgrammar/tars.tab.cpp index eb0aca62..ee40db41 100644 --- a/tools/tarsgrammar/tars.tab.cpp +++ b/tools/tarsgrammar/tars.tab.cpp @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.7.6. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, - Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 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 @@ -16,7 +15,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 @@ -34,10 +33,6 @@ /* 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. @@ -45,11 +40,11 @@ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -/* Identify Bison output, and Bison version. */ -#define YYBISON 30706 +/* Identify Bison output. */ +#define YYBISON 1 -/* Bison version string. */ -#define YYBISON_VERSION "3.7.6" +/* Bison version. */ +#define YYBISON_VERSION "3.0.4" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -66,8 +61,8 @@ -/* First part of user prologue. */ -#line 17 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" +/* Copy the first part of user declarations. */ +#line 17 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:339 */ #include #include @@ -81,213 +76,119 @@ using namespace std; #define YYDEBUG 1 #define YYINITDEPTH 10000 -#line 85 "tars.tab.cpp" +#line 80 "tars.tab.cpp" /* yacc.c:339 */ -# 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 -# if 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULLPTR nullptr # else -# define YY_NULLPTR ((void*)0) +# define YY_NULLPTR 0 # endif # 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; - +/* 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 -#ifdef short -# undef short +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef int YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 #endif -/* 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. */ -#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 +extern YYSTYPE yylval; -/* 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. */ +int yyparse (void); -#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 +#endif /* !YY_YY_TARS_TAB_HPP_INCLUDED */ -#ifdef __INT_LEAST16_MAX__ -typedef __INT_LEAST16_TYPE__ yytype_int16; -#elif defined YY_STDINT_H -typedef int_least16_t yytype_int16; -#else -typedef short yytype_int16; -#endif +/* Copy the second part of user declarations. */ + +#line 165 "tars.tab.cpp" /* yacc.c:358 */ -/* 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 +#ifdef short +# undef short #endif -#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 +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; #else -typedef short yytype_uint8; +typedef signed char yytype_int8; #endif -#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; +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; #else -typedef int yytype_uint16; +typedef unsigned short 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 +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; #endif #ifndef YYSIZE_T @@ -295,28 +196,15 @@ typedef int yytype_uint16; # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# elif ! defined YYSIZE_T # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else -# define YYSIZE_T unsigned +# define YYSIZE_T unsigned int # endif #endif -#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; +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS @@ -330,37 +218,47 @@ typedef int yy_state_fast_t; # endif #endif - -#ifndef YY_ATTRIBUTE_PURE -# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) -# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +#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_PURE +# define YY_ATTRIBUTE(Spec) /* empty */ # endif #endif +#ifndef YY_ATTRIBUTE_PURE +# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#endif + #ifndef YY_ATTRIBUTE_UNUSED -# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) -# define YY_ATTRIBUTE_UNUSED __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) # else -# define YY_ATTRIBUTE_UNUSED +# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YY_USE(E) ((void) (E)) +# define YYUSE(E) ((void) (E)) #else -# define YY_USE(E) /* empty */ +# define YYUSE(E) /* empty */ #endif -#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +#if defined __GNUC__ && 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 @@ -373,22 +271,8 @@ typedef int yy_state_fast_t; # 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 - -#define YY_ASSERT(E) ((void) (0 && (E))) - -#if !defined yyoverflow +#if ! defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -453,7 +337,8 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif -#endif /* !defined yyoverflow */ +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + #if (! defined yyoverflow \ && (! defined __cplusplus \ @@ -462,17 +347,17 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ /* A type that is properly aligned for any stack member. */ union yyalloc { - yy_state_t yyss_alloc; + yytype_int16 yyss_alloc; YYSTYPE yyvs_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ - ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) # define YYCOPY_NEEDED 1 @@ -485,11 +370,11 @@ union yyalloc # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ - YYPTRDIFF_T yynewbytes; \ + YYSIZE_T yynewbytes; \ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / YYSIZEOF (*yyptr); \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ } \ while (0) @@ -501,12 +386,12 @@ union yyalloc # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) + __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) # else # define YYCOPY(Dst, Src, Count) \ do \ { \ - YYPTRDIFF_T yyi; \ + YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (Dst)[yyi] = (Src)[yyi]; \ } \ @@ -529,20 +414,17 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES 199 -/* YYMAXUTOK -- Last valid token kind. */ +/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned + by yylex, with out-of-bounds checking. */ +#define YYUNDEFTOK 2 #define YYMAXUTOK 288 - -/* 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) +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM - as returned by yylex. */ -static const yytype_int8 yytranslate[] = + as returned by yylex, without out-of-bounds checking. */ +static const yytype_uint8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -577,7 +459,7 @@ static const yytype_int8 yytranslate[] = #if YYDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_int16 yyrline[] = +static const yytype_uint16 yyrline[] = { 0, 68, 68, 75, 74, 79, 78, 83, 88, 95, 99, 103, 107, 110, 114, 124, 123, 146, 159, 170, @@ -596,48 +478,35 @@ static const yytype_int16 yyrline[] = }; #endif -/** 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; - +#if YYDEBUG || YYERROR_VERBOSE || 0 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "\"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 + "$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 }; - -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_int16 yytoknum[] = +static const yytype_uint16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, @@ -645,16 +514,16 @@ static const yytype_int16 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(Yyn) \ - ((Yyn) == YYPACT_NINF) +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-146))) -#define YYTABLE_NINF (-113) +#define YYTABLE_NINF -113 -#define yytable_value_is_error(Yyn) \ +#define yytable_value_is_error(Yytable_value) \ 0 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing @@ -721,9 +590,9 @@ static const yytype_int16 yypgoto[] = }; /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_uint8 yydefgoto[] = +static const yytype_int16 yydefgoto[] = { - 0, 8, 9, 76, 80, 10, 11, 77, 12, 123, + -1, 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, @@ -857,7 +726,7 @@ static const yytype_int16 yycheck[] = /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ -static const yytype_int8 yystos[] = +static const yytype_uint8 yystos[] = { 0, 1, 4, 15, 16, 20, 30, 31, 47, 48, 51, 52, 54, 57, 59, 62, 64, 73, 75, 80, @@ -882,7 +751,7 @@ static const yytype_int8 yystos[] = }; /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_int8 yyr1[] = +static const yytype_uint8 yyr1[] = { 0, 46, 47, 49, 48, 50, 48, 48, 48, 51, 51, 51, 51, 51, 51, 53, 52, 54, 54, 55, @@ -901,7 +770,7 @@ static const yytype_int8 yyr1[] = }; /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_int8 yyr2[] = +static const yytype_uint8 yyr2[] = { 0, 2, 1, 0, 4, 0, 4, 1, 0, 1, 1, 1, 1, 1, 1, 0, 5, 2, 2, 3, @@ -920,10 +789,10 @@ static const yytype_int8 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 @@ -932,26 +801,27 @@ enum { YYENOMEM = -2 }; #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) - -/* Backward compatibility with an undocumented macro. - Use YYerror or YYUNDEF. */ -#define YYERRCODE YYUNDEF +#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 + /* Enable debugging if requested. */ @@ -969,58 +839,54 @@ 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, Kind, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Kind, Value); \ + Type, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) -/*-----------------------------------. -| Print this symbol's value on YYO. | -`-----------------------------------*/ +/*----------------------------------------. +| Print this symbol's value on YYOUTPUT. | +`----------------------------------------*/ static void -yy_symbol_value_print (FILE *yyo, - yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) { - FILE *yyoutput = yyo; - YY_USE (yyoutput); + FILE *yyo = yyoutput; + YYUSE (yyo); if (!yyvaluep) return; # ifdef YYPRINT - if (yykind < YYNTOKENS) - YYPRINT (yyo, yytoknum[yykind], *yyvaluep); + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); # endif - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YY_USE (yykind); - YY_IGNORE_MAYBE_UNINITIALIZED_END + YYUSE (yytype); } -/*---------------------------. -| Print this symbol on YYO. | -`---------------------------*/ +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ static void -yy_symbol_print (FILE *yyo, - yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) { - YYFPRINTF (yyo, "%s %s (", - yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); + YYFPRINTF (yyoutput, "%s %s (", + yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); - yy_symbol_value_print (yyo, yykind, yyvaluep); - YYFPRINTF (yyo, ")"); + yy_symbol_value_print (yyoutput, yytype, yyvaluep); + YYFPRINTF (yyoutput, ")"); } /*------------------------------------------------------------------. @@ -1029,7 +895,7 @@ yy_symbol_print (FILE *yyo, `------------------------------------------------------------------*/ static void -yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -1052,21 +918,21 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, - int yyrule) +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) { - int yylno = yyrline[yyrule]; + unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, - YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), - &yyvsp[(yyi + 1) - (yynrhs)]); + yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)]) + ); YYFPRINTF (stderr, "\n"); } } @@ -1081,8 +947,8 @@ do { \ multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) ((void) 0) -# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ @@ -1105,30 +971,249 @@ 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, - yysymbol_kind_t yykind, YYSTYPE *yyvaluep) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) { - YY_USE (yyvaluep); + YYUSE (yyvaluep); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YY_USE (yykind); + YYUSE (yytype); YY_IGNORE_MAYBE_UNINITIALIZED_END } -/* Lookahead token kind. */ + + +/* The lookahead symbol. */ int yychar; /* The semantic value of the lookahead symbol. */ @@ -1137,8 +1222,6 @@ YYSTYPE yylval; int yynerrs; - - /*----------. | yyparse. | `----------*/ @@ -1146,36 +1229,43 @@ int yynerrs; int yyparse (void) { - yy_state_fast_t yystate = 0; + int yystate; /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus = 0; + int yyerrstatus; - /* Refer to the stacks through separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ + /* The stacks and their tools: + 'yyss': related to states. + 'yyvs': related to semantic values. - /* Their size. */ - YYPTRDIFF_T yystacksize = YYINITDEPTH; + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ - /* The state stack: array, bottom, top. */ - yy_state_t yyssa[YYINITDEPTH]; - yy_state_t *yyss = yyssa; - yy_state_t *yyssp = yyss; + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; - /* The semantic value stack: array, bottom, top. */ + /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs = yyvsa; - YYSTYPE *yyvsp = yyvs; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + YYSIZE_T yystacksize; int yyn; - /* The return value of yyparse. */ int yyresult; - /* Lookahead symbol kind. */ - yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; + /* Lookahead token as an internal (translated) token number. */ + int yytoken = 0; /* 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)) @@ -1183,60 +1273,58 @@ 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 -- 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); + yysetstate: + *yyssp = yystate; 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. */ - YYPTRDIFF_T yysize = yyssp - yyss + 1; + YYSIZE_T yysize = yyssp - yyss + 1; -# if defined yyoverflow +#ifdef 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 * YYSIZEOF (*yyssp), - &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); + yyss = yyss1; yyvs = yyvs1; } -# else /* defined YYSTACK_RELOCATE */ +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; @@ -1245,10 +1333,9 @@ yyparse (void) yystacksize = YYMAXDEPTH; { - yy_state_t *yyss1 = yyss; + yytype_int16 *yyss1 = yyss; union yyalloc *yyptr = - YY_CAST (union yyalloc *, - YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); @@ -1258,30 +1345,30 @@ yyparse (void) YYSTACK_FREE (yyss1); } # endif +#endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; - YY_IGNORE_USELESS_CAST_BEGIN - YYDPRINTF ((stderr, "Stack size increased to %ld\n", - YY_CAST (long, yystacksize))); - YY_IGNORE_USELESS_CAST_END + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) YYABORT; } -#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 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. */ @@ -1292,29 +1379,18 @@ yyparse (void) /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { - YYDPRINTF ((stderr, "Reading a token\n")); + YYDPRINTF ((stderr, "Reading a token: ")); yychar = yylex (); } if (yychar <= YYEOF) { - yychar = YYEOF; - yytoken = YYSYMBOL_YYEOF; + yychar = yytoken = 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); @@ -1342,13 +1418,15 @@ 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; @@ -1363,7 +1441,7 @@ yyparse (void) /*-----------------------------. -| yyreduce -- do a reduction. | +| yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ @@ -1383,238 +1461,238 @@ yyparse (void) YY_REDUCE_PRINT (yyn); switch (yyn) { - case 3: /* $@1: %empty */ -#line 75 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 3: +#line 75 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1391 "tars.tab.cpp" +#line 1469 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 5: /* $@2: %empty */ -#line 79 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 5: +#line 79 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { yyerrok; } -#line 1399 "tars.tab.cpp" +#line 1477 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 7: /* definitions: definition */ -#line 84 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 7: +#line 84 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("`;' missing after definition"); } -#line 1407 "tars.tab.cpp" +#line 1485 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 8: /* definitions: %empty */ -#line 88 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 8: +#line 88 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1414 "tars.tab.cpp" +#line 1492 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 9: /* definition: namespace_def */ -#line 96 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - assert(yyvsp[0] == 0 || NamespacePtr::dynamicCast(yyvsp[0])); + case 9: +#line 96 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + assert((yyvsp[0]) == 0 || NamespacePtr::dynamicCast((yyvsp[0]))); } -#line 1422 "tars.tab.cpp" +#line 1500 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 10: /* definition: interface_def */ -#line 100 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - assert(yyvsp[0] == 0 || InterfacePtr::dynamicCast(yyvsp[0])); + case 10: +#line 100 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + assert((yyvsp[0]) == 0 || InterfacePtr::dynamicCast((yyvsp[0]))); } -#line 1430 "tars.tab.cpp" +#line 1508 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 11: /* definition: struct_def */ -#line 104 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - assert(yyvsp[0] == 0 || StructPtr::dynamicCast(yyvsp[0])); + case 11: +#line 104 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + assert((yyvsp[0]) == 0 || StructPtr::dynamicCast((yyvsp[0]))); } -#line 1438 "tars.tab.cpp" +#line 1516 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 12: /* definition: key_def */ -#line 108 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 12: +#line 108 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1445 "tars.tab.cpp" +#line 1523 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 13: /* definition: enum_def */ -#line 111 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - assert(yyvsp[0] == 0 || EnumPtr::dynamicCast(yyvsp[0])); + case 13: +#line 111 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + assert((yyvsp[0]) == 0 || EnumPtr::dynamicCast((yyvsp[0]))); } -#line 1453 "tars.tab.cpp" +#line 1531 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 14: /* definition: const_def */ -#line 115 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - assert(yyvsp[0] == 0 || ConstPtr::dynamicCast(yyvsp[0])); + case 14: +#line 115 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + assert((yyvsp[0]) == 0 || ConstPtr::dynamicCast((yyvsp[0]))); } -#line 1461 "tars.tab.cpp" +#line 1539 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 15: /* @3: %empty */ -#line 124 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = yyvsp[0]; + case 15: +#line 124 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = (yyvsp[0]); } -#line 1469 "tars.tab.cpp" +#line 1547 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 16: /* enum_def: enum_id @3 '{' enumerator_list '}' */ -#line 128 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - if(yyvsp[-2]) + case 16: +#line 128 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + if((yyvsp[-2])) { g_parse->popContainer(); - yyval = yyvsp[-2]; + (yyval) = (yyvsp[-2]); } else { - yyval = 0; + (yyval) = 0; } - yyval = yyvsp[-3]; + (yyval) = (yyvsp[-3]); } -#line 1487 "tars.tab.cpp" +#line 1565 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 17: /* enum_id: TARS_ENUM TARS_IDENTIFIER */ -#line 147 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 17: +#line 147 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 1504 "tars.tab.cpp" +#line 1582 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 18: /* enum_id: TARS_ENUM keyword */ -#line 160 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 18: +#line 160 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 1514 "tars.tab.cpp" +#line 1592 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 19: /* enumerator_list: enumerator ',' enumerator_list */ -#line 171 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = yyvsp[-1]; + case 19: +#line 171 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = (yyvsp[-1]); } -#line 1522 "tars.tab.cpp" +#line 1600 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 20: /* enumerator_list: enumerator */ -#line 175 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 20: +#line 175 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1529 "tars.tab.cpp" +#line 1607 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 21: /* enumerator: TARS_IDENTIFIER */ -#line 183 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 21: +#line 183 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 1544 "tars.tab.cpp" +#line 1622 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 22: /* enumerator: keyword */ -#line 194 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 22: +#line 194 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); g_parse->error("keyword `" + ident->v + "' cannot be used as enumerator"); } -#line 1553 "tars.tab.cpp" +#line 1631 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 23: /* enumerator: TARS_IDENTIFIER '=' const_initializer */ -#line 199 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 23: +#line 199 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 1570 "tars.tab.cpp" +#line 1648 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 24: /* enumerator: %empty */ -#line 212 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 24: +#line 212 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1577 "tars.tab.cpp" +#line 1655 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 25: /* @4: %empty */ -#line 220 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 25: +#line 220 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 1596 "tars.tab.cpp" +#line 1674 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 26: /* namespace_def: TARS_NAMESPACE TARS_IDENTIFIER @4 '{' definitions '}' */ -#line 235 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - if(yyvsp[-3]) + case 26: +#line 235 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + if((yyvsp[-3])) { g_parse->popContainer(); - yyval = yyvsp[-3]; + (yyval) = (yyvsp[-3]); } else { - yyval = 0; + (yyval) = 0; } } -#line 1612 "tars.tab.cpp" +#line 1690 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 27: /* $@5: %empty */ -#line 253 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-1]); + case 27: +#line 253 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[-1])); StructPtr sp = StructPtr::dynamicCast(g_parse->findUserType(ident->v)); if(!sp) { @@ -1623,20 +1701,20 @@ yyparse (void) g_parse->setKeyStruct(sp); } -#line 1627 "tars.tab.cpp" +#line 1705 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 28: /* key_def: TARS_KEY '[' scoped_name ',' $@5 key_members ']' */ -#line 264 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 28: +#line 264 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1634 "tars.tab.cpp" +#line 1712 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 29: /* key_members: TARS_IDENTIFIER */ -#line 272 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 29: +#line 272 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); StructPtr np = g_parse->getKeyStruct(); if(np) { @@ -1644,16 +1722,16 @@ yyparse (void) } else { - yyval = 0; + (yyval) = 0; } } -#line 1651 "tars.tab.cpp" +#line 1729 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 30: /* key_members: key_members ',' TARS_IDENTIFIER */ -#line 285 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 30: +#line 285 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); StructPtr np = g_parse->getKeyStruct(); if(np) { @@ -1661,16 +1739,16 @@ yyparse (void) } else { - yyval = 0; + (yyval) = 0; } } -#line 1668 "tars.tab.cpp" +#line 1746 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 31: /* @6: %empty */ -#line 304 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 31: +#line 304 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); NamespacePtr c = NamespacePtr::dynamicCast(g_parse->currentContainer()); @@ -1678,100 +1756,100 @@ yyparse (void) if(cl) { g_parse->pushContainer(cl); - yyval = GrammarBasePtr::dynamicCast(cl); + (yyval) = GrammarBasePtr::dynamicCast(cl); } else { - yyval = 0; + (yyval) = 0; } } -#line 1689 "tars.tab.cpp" +#line 1767 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 32: /* interface_def: interface_id @6 '{' interface_exports '}' */ -#line 321 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - if(yyvsp[-3]) + case 32: +#line 321 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + if((yyvsp[-3])) { g_parse->popContainer(); - yyval = GrammarBasePtr::dynamicCast(yyvsp[-3]); + (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-3])); } else { - yyval = 0; + (yyval) = 0; } } -#line 1705 "tars.tab.cpp" +#line 1783 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 33: /* interface_id: TARS_INTERFACE TARS_IDENTIFIER */ -#line 338 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = yyvsp[0]; + case 33: +#line 338 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = (yyvsp[0]); } -#line 1713 "tars.tab.cpp" +#line 1791 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 34: /* interface_id: TARS_INTERFACE keyword */ -#line 342 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 34: +#line 342 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 1723 "tars.tab.cpp" +#line 1801 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 35: /* interface_exports: interface_export ';' interface_exports */ -#line 353 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 35: +#line 353 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1730 "tars.tab.cpp" +#line 1808 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 36: /* interface_exports: error ';' interface_exports */ -#line 356 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 36: +#line 356 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1737 "tars.tab.cpp" +#line 1815 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 37: /* interface_exports: interface_export */ -#line 359 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 37: +#line 359 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("`;' missing after definition"); } -#line 1745 "tars.tab.cpp" +#line 1823 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 38: /* interface_exports: %empty */ -#line 363 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 38: +#line 363 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1752 "tars.tab.cpp" +#line 1830 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 40: /* operation: operation_preamble parameters ')' */ -#line 377 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - if(yyvsp[-2]) + case 40: +#line 377 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + if((yyvsp[-2])) { g_parse->popContainer(); - yyval = GrammarBasePtr::dynamicCast(yyvsp[-2]); + (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-2])); } else { - yyval = 0; + (yyval) = 0; } } -#line 1768 "tars.tab.cpp" +#line 1846 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 41: /* operation_preamble: return_type TARS_OP */ -#line 394 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypePtr returnType = TypePtr::dynamicCast(yyvsp[-1]); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + 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])); string name = ident->v; InterfacePtr cl = InterfacePtr::dynamicCast(g_parse->currentContainer()); if(cl) @@ -1780,40 +1858,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 1796 "tars.tab.cpp" +#line 1874 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 43: /* return_type: TARS_VOID */ -#line 424 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = 0; + case 43: +#line 424 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = 0; } -#line 1804 "tars.tab.cpp" +#line 1882 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 44: /* parameters: %empty */ -#line 434 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 44: +#line 434 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1811 "tars.tab.cpp" +#line 1889 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 45: /* parameters: type_id */ -#line 437 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + case 45: +#line 437 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1822,13 +1900,13 @@ yyparse (void) op->createParamDecl(tsp, false, false); } } -#line 1826 "tars.tab.cpp" +#line 1904 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 46: /* parameters: parameters ',' type_id */ -#line 448 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + case 46: +#line 448 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1837,14 +1915,14 @@ yyparse (void) op->createParamDecl(tsp, false, false); } } -#line 1841 "tars.tab.cpp" +#line 1919 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 47: /* parameters: out_qualifier type_id */ -#line 459 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + 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])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1853,14 +1931,14 @@ yyparse (void) op->createParamDecl(tsp, isOutParam->v, false); } } -#line 1857 "tars.tab.cpp" +#line 1935 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 48: /* parameters: parameters ',' out_qualifier type_id */ -#line 471 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + 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])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1869,14 +1947,14 @@ yyparse (void) op->createParamDecl(tsp, isOutParam->v, false); } } -#line 1873 "tars.tab.cpp" +#line 1951 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 49: /* parameters: routekey_qualifier type_id */ -#line 483 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + 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])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1885,14 +1963,14 @@ yyparse (void) op->createParamDecl(tsp, false, isRouteKeyParam->v); } } -#line 1889 "tars.tab.cpp" +#line 1967 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 50: /* parameters: parameters ',' routekey_qualifier type_id */ -#line 495 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + 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])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1901,49 +1979,49 @@ yyparse (void) op->createParamDecl(tsp, false, isRouteKeyParam->v); } } -#line 1905 "tars.tab.cpp" +#line 1983 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 51: /* parameters: out_qualifier */ -#line 507 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 51: +#line 507 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("'out' must be defined with a type"); } -#line 1913 "tars.tab.cpp" +#line 1991 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 52: /* parameters: routekey_qualifier */ -#line 511 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 52: +#line 511 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("'routekey' must be defined with a type"); } -#line 1921 "tars.tab.cpp" +#line 1999 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 53: /* routekey_qualifier: TARS_ROUTE_KEY */ -#line 520 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 53: +#line 520 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { BoolGrammarPtr routekey = new BoolGrammar; routekey->v = true; - yyval = GrammarBasePtr::dynamicCast(routekey); + (yyval) = GrammarBasePtr::dynamicCast(routekey); } -#line 1931 "tars.tab.cpp" +#line 2009 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 54: /* out_qualifier: TARS_OUT */ -#line 531 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 54: +#line 531 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { BoolGrammarPtr out = new BoolGrammar; out->v = true; - yyval = GrammarBasePtr::dynamicCast(out); + (yyval) = GrammarBasePtr::dynamicCast(out); } -#line 1941 "tars.tab.cpp" +#line 2019 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 55: /* @7: %empty */ -#line 542 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 55: +#line 542 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); NamespacePtr np = NamespacePtr::dynamicCast(g_parse->currentContainer()); if(np) { @@ -1951,11 +2029,11 @@ yyparse (void) if(sp) { g_parse->pushContainer(sp); - yyval = GrammarBasePtr::dynamicCast(sp); + (yyval) = GrammarBasePtr::dynamicCast(sp); } else { - yyval = 0; + (yyval) = 0; } } else @@ -1963,280 +2041,280 @@ yyparse (void) g_parse->error("struct '" + ident->v + "' must definition in namespace"); } } -#line 1967 "tars.tab.cpp" +#line 2045 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 56: /* struct_def: struct_id @7 '{' struct_exports '}' */ -#line 564 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - if(yyvsp[-3]) + case 56: +#line 564 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 1986 "tars.tab.cpp" +#line 2064 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 57: /* struct_id: TARS_STRUCT TARS_IDENTIFIER */ -#line 584 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = yyvsp[0]; + case 57: +#line 584 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = (yyvsp[0]); } -#line 1994 "tars.tab.cpp" +#line 2072 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 58: /* struct_id: TARS_STRUCT keyword */ -#line 588 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 58: +#line 588 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); g_parse->error("keyword `" + ident->v + "' cannot be used as struct name"); } -#line 2004 "tars.tab.cpp" +#line 2082 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 59: /* struct_id: TARS_STRUCT error */ -#line 594 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 59: +#line 594 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("abstract declarator '' used as declaration"); } -#line 2012 "tars.tab.cpp" +#line 2090 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 60: /* struct_exports: data_member ';' struct_exports */ -#line 603 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 60: +#line 603 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2020 "tars.tab.cpp" +#line 2098 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 61: /* struct_exports: data_member */ -#line 607 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 61: +#line 607 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("';' missing after definition"); } -#line 2028 "tars.tab.cpp" +#line 2106 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 62: /* struct_exports: %empty */ -#line 611 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 62: +#line 611 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2035 "tars.tab.cpp" +#line 2113 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 63: /* data_member: struct_type_id */ -#line 621 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); + case 63: +#line 621 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); } -#line 2043 "tars.tab.cpp" +#line 2121 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 64: /* struct_type_id: TARS_CONST_INTEGER TARS_REQUIRE type_id */ -#line 630 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 64: +#line 630 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 2065 "tars.tab.cpp" +#line 2143 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 65: /* struct_type_id: TARS_CONST_INTEGER TARS_REQUIRE type_id '=' const_initializer */ -#line 648 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 65: +#line 648 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 2091 "tars.tab.cpp" +#line 2169 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 66: /* struct_type_id: TARS_CONST_INTEGER TARS_OPTIONAL type_id '=' const_initializer */ -#line 670 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 66: +#line 670 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 2117 "tars.tab.cpp" +#line 2195 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 67: /* struct_type_id: TARS_CONST_INTEGER TARS_OPTIONAL type_id */ -#line 692 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 67: +#line 692 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 2138 "tars.tab.cpp" +#line 2216 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 68: /* struct_type_id: TARS_REQUIRE type_id */ -#line 709 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 68: +#line 709 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("struct member need 'tag'"); } -#line 2146 "tars.tab.cpp" +#line 2224 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 69: /* struct_type_id: TARS_OPTIONAL type_id */ -#line 713 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 69: +#line 713 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("struct member need 'tag'"); } -#line 2154 "tars.tab.cpp" +#line 2232 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 70: /* struct_type_id: TARS_CONST_INTEGER type_id */ -#line 717 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 70: +#line 717 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("struct member need 'require' or 'optional'"); } -#line 2162 "tars.tab.cpp" +#line 2240 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 71: /* struct_type_id: type_id */ -#line 721 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 71: +#line 721 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("struct member need 'tag' or 'require' or 'optional'"); } -#line 2170 "tars.tab.cpp" +#line 2248 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 72: /* const_initializer: TARS_CONST_INTEGER */ -#line 730 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - IntergerGrammarPtr intVal = IntergerGrammarPtr::dynamicCast(yyvsp[0]); + case 72: +#line 730 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 2184 "tars.tab.cpp" +#line 2262 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 73: /* const_initializer: TARS_CONST_FLOAT */ -#line 740 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - FloatGrammarPtr floatVal = FloatGrammarPtr::dynamicCast(yyvsp[0]); + case 73: +#line 740 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 2198 "tars.tab.cpp" +#line 2276 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 74: /* const_initializer: TARS_STRING_LITERAL */ -#line 750 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 74: +#line 750 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::STRING; c->v = ident->v; - yyval = c; + (yyval) = c; } -#line 2210 "tars.tab.cpp" +#line 2288 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 75: /* const_initializer: TARS_FALSE */ -#line 758 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 75: +#line 758 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::BOOL; c->v = ident->v; - yyval = c; + (yyval) = c; } -#line 2222 "tars.tab.cpp" +#line 2300 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 76: /* const_initializer: TARS_TRUE */ -#line 766 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 76: +#line 766 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::BOOL; c->v = ident->v; - yyval = c; + (yyval) = c; } -#line 2234 "tars.tab.cpp" +#line 2312 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 77: /* const_initializer: TARS_IDENTIFIER */ -#line 774 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 77: +#line 774 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); if (g_parse->checkEnum(ident->v) == false) { @@ -2245,17 +2323,17 @@ yyparse (void) ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::ENUM; c->v = ident->v; - yyval = c; + (yyval) = c; } -#line 2251 "tars.tab.cpp" +#line 2329 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 78: /* const_initializer: scoped_name TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ -#line 787 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 78: +#line 787 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { - 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) { @@ -2264,512 +2342,511 @@ yyparse (void) ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::ENUM; c->v = scoped->v + "::" + ident->v; - yyval = c; + (yyval) = c; } -#line 2270 "tars.tab.cpp" +#line 2348 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 79: /* const_def: TARS_CONST type_id '=' const_initializer */ -#line 807 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 79: +#line 807 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 2287 "tars.tab.cpp" +#line 2365 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 80: /* type_id: type TARS_IDENTIFIER */ -#line 825 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypePtr type = TypePtr::dynamicCast(yyvsp[-1]); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + 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])); TypeIdPtr typeIdPtr = new TypeId(type, ident->v); - yyval = GrammarBasePtr::dynamicCast(typeIdPtr); + (yyval) = GrammarBasePtr::dynamicCast(typeIdPtr); } -#line 2300 "tars.tab.cpp" +#line 2378 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 81: /* type_id: type TARS_IDENTIFIER '[' TARS_CONST_INTEGER ']' */ -#line 834 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypePtr type = g_parse->createVector(TypePtr::dynamicCast(yyvsp[-4])); - IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast(yyvsp[-1]); + 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])); 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 2314 "tars.tab.cpp" +#line 2392 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 82: /* type_id: type '*' TARS_IDENTIFIER */ -#line 844 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypePtr type = g_parse->createVector(TypePtr::dynamicCast(yyvsp[-2])); + case 82: +#line 844 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 2328 "tars.tab.cpp" +#line 2406 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 83: /* type_id: type TARS_IDENTIFIER ':' TARS_CONST_INTEGER */ -#line 854 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypePtr type = TypePtr::dynamicCast(yyvsp[-3]); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-2]); + 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])); 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 2341 "tars.tab.cpp" +#line 2419 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 84: /* type_id: type keyword */ -#line 863 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 84: +#line 863 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); g_parse->error("keyword `" + ident->v + "' cannot be used as data member name"); } -#line 2350 "tars.tab.cpp" +#line 2428 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 85: /* type_id: type */ -#line 868 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 85: +#line 868 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("missing data member name"); } -#line 2358 "tars.tab.cpp" +#line 2436 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 86: /* type_id: error */ -#line 872 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 86: +#line 872 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("unkown type"); } -#line 2366 "tars.tab.cpp" +#line 2444 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 87: /* type: type_no ':' TARS_CONST_INTEGER */ -#line 881 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 87: +#line 881 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { - 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 2379 "tars.tab.cpp" +#line 2457 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 88: /* type: type_no */ -#line 890 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = yyvsp[0]; + case 88: +#line 890 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = (yyvsp[0]); } -#line 2387 "tars.tab.cpp" +#line 2465 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 89: /* type: type_no ':' error */ -#line 894 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 89: +#line 894 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("array missing size"); } -#line 2395 "tars.tab.cpp" +#line 2473 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 90: /* type_no: TARS_BOOL */ -#line 903 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindBool); + case 90: +#line 903 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindBool); } -#line 2403 "tars.tab.cpp" +#line 2481 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 91: /* type_no: TARS_BYTE */ -#line 907 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindByte); + case 91: +#line 907 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindByte); } -#line 2411 "tars.tab.cpp" +#line 2489 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 92: /* type_no: TARS_UNSIGNED TARS_BYTE */ -#line 911 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindShort,true); + case 92: +#line 911 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindShort,true); } -#line 2419 "tars.tab.cpp" +#line 2497 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 93: /* type_no: TARS_SHORT */ -#line 915 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindShort); + case 93: +#line 915 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindShort); } -#line 2427 "tars.tab.cpp" +#line 2505 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 94: /* type_no: TARS_UNSIGNED TARS_SHORT */ -#line 919 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindInt,true); + case 94: +#line 919 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindInt,true); } -#line 2435 "tars.tab.cpp" +#line 2513 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 95: /* type_no: TARS_INT */ -#line 923 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindInt); + case 95: +#line 923 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindInt); } -#line 2443 "tars.tab.cpp" +#line 2521 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 96: /* type_no: TARS_UNSIGNED TARS_INT */ -#line 927 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindLong,true); + case 96: +#line 927 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindLong,true); } -#line 2451 "tars.tab.cpp" +#line 2529 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 97: /* type_no: TARS_LONG */ -#line 931 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindLong); + case 97: +#line 931 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindLong); } -#line 2459 "tars.tab.cpp" +#line 2537 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 98: /* type_no: TARS_FLOAT */ -#line 935 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindFloat); + case 98: +#line 935 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindFloat); } -#line 2467 "tars.tab.cpp" +#line 2545 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 99: /* type_no: TARS_DOUBLE */ -#line 939 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindDouble); + case 99: +#line 939 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindDouble); } -#line 2475 "tars.tab.cpp" +#line 2553 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 100: /* type_no: TARS_STRING */ -#line 943 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindString); + case 100: +#line 943 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindString); } -#line 2483 "tars.tab.cpp" +#line 2561 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 101: /* type_no: vector */ -#line 947 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); + case 101: +#line 947 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); } -#line 2491 "tars.tab.cpp" +#line 2569 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 102: /* type_no: map */ -#line 951 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); + case 102: +#line 951 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); } -#line 2499 "tars.tab.cpp" +#line 2577 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 103: /* type_no: scoped_name */ -#line 955 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 103: +#line 955 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 2516 "tars.tab.cpp" +#line 2594 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 104: /* vector: TARS_VECTOR '<' type '>' */ -#line 973 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = GrammarBasePtr::dynamicCast(g_parse->createVector(TypePtr::dynamicCast(yyvsp[-1]))); + case 104: +#line 973 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = GrammarBasePtr::dynamicCast(g_parse->createVector(TypePtr::dynamicCast((yyvsp[-1])))); } -#line 2524 "tars.tab.cpp" +#line 2602 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 105: /* vector: TARS_VECTOR '<' error */ -#line 977 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 105: +#line 977 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("vector error"); } -#line 2532 "tars.tab.cpp" +#line 2610 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 106: /* vector: TARS_VECTOR '<' type error */ -#line 981 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 106: +#line 981 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("vector missing '>'"); } -#line 2540 "tars.tab.cpp" +#line 2618 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 107: /* vector: TARS_VECTOR error */ -#line 985 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 107: +#line 985 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("vector missing type"); } -#line 2548 "tars.tab.cpp" +#line 2626 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 108: /* map: TARS_MAP '<' type ',' type '>' */ -#line 994 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = GrammarBasePtr::dynamicCast(g_parse->createMap(TypePtr::dynamicCast(yyvsp[-3]), TypePtr::dynamicCast(yyvsp[-1]))); + 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])))); } -#line 2556 "tars.tab.cpp" +#line 2634 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 109: /* map: TARS_MAP '<' error */ -#line 998 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 109: +#line 998 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("map error"); } -#line 2564 "tars.tab.cpp" +#line 2642 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 110: /* scoped_name: TARS_IDENTIFIER */ -#line 1007 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 110: +#line 1007 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2571 "tars.tab.cpp" +#line 2649 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 111: /* scoped_name: TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ -#line 1010 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 111: +#line 1010 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); ident->v = "::" + ident->v; - yyval = GrammarBasePtr::dynamicCast(ident); + (yyval) = GrammarBasePtr::dynamicCast(ident); } -#line 2581 "tars.tab.cpp" +#line 2659 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 112: /* scoped_name: scoped_name TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ -#line 1016 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr scoped = StringGrammarPtr::dynamicCast(yyvsp[-2]); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + 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])); scoped->v += "::"; scoped->v += ident->v; - yyval = GrammarBasePtr::dynamicCast(scoped); + (yyval) = GrammarBasePtr::dynamicCast(scoped); } -#line 2593 "tars.tab.cpp" +#line 2671 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 113: /* keyword: TARS_STRUCT */ -#line 1029 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 113: +#line 1029 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2600 "tars.tab.cpp" +#line 2678 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 114: /* keyword: TARS_VOID */ -#line 1032 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 114: +#line 1032 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2607 "tars.tab.cpp" +#line 2685 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 115: /* keyword: TARS_BOOL */ -#line 1035 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 115: +#line 1035 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2614 "tars.tab.cpp" +#line 2692 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 116: /* keyword: TARS_BYTE */ -#line 1038 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 116: +#line 1038 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2621 "tars.tab.cpp" +#line 2699 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 117: /* keyword: TARS_SHORT */ -#line 1041 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 117: +#line 1041 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2628 "tars.tab.cpp" +#line 2706 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 118: /* keyword: TARS_INT */ -#line 1044 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 118: +#line 1044 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2635 "tars.tab.cpp" +#line 2713 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 119: /* keyword: TARS_FLOAT */ -#line 1047 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 119: +#line 1047 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2642 "tars.tab.cpp" +#line 2720 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 120: /* keyword: TARS_DOUBLE */ -#line 1050 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 120: +#line 1050 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2649 "tars.tab.cpp" +#line 2727 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 121: /* keyword: TARS_STRING */ -#line 1053 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 121: +#line 1053 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2656 "tars.tab.cpp" +#line 2734 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 122: /* keyword: TARS_VECTOR */ -#line 1056 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 122: +#line 1056 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2663 "tars.tab.cpp" +#line 2741 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 123: /* keyword: TARS_KEY */ -#line 1059 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 123: +#line 1059 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2670 "tars.tab.cpp" +#line 2748 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 124: /* keyword: TARS_MAP */ -#line 1062 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 124: +#line 1062 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2677 "tars.tab.cpp" +#line 2755 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 125: /* keyword: TARS_NAMESPACE */ -#line 1065 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 125: +#line 1065 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2684 "tars.tab.cpp" +#line 2762 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 126: /* keyword: TARS_INTERFACE */ -#line 1068 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 126: +#line 1068 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2691 "tars.tab.cpp" +#line 2769 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 127: /* keyword: TARS_OUT */ -#line 1071 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 127: +#line 1071 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2698 "tars.tab.cpp" +#line 2776 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 128: /* keyword: TARS_REQUIRE */ -#line 1074 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 128: +#line 1074 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2705 "tars.tab.cpp" +#line 2783 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 129: /* keyword: TARS_OPTIONAL */ -#line 1077 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 129: +#line 1077 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2712 "tars.tab.cpp" +#line 2790 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 130: /* keyword: TARS_CONST_INTEGER */ -#line 1080 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 130: +#line 1080 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2719 "tars.tab.cpp" +#line 2797 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 131: /* keyword: TARS_CONST_FLOAT */ -#line 1083 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 131: +#line 1083 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2726 "tars.tab.cpp" +#line 2804 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 132: /* keyword: TARS_FALSE */ -#line 1086 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 132: +#line 1086 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2733 "tars.tab.cpp" +#line 2811 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 133: /* keyword: TARS_TRUE */ -#line 1089 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 133: +#line 1089 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2740 "tars.tab.cpp" +#line 2818 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 134: /* keyword: TARS_STRING_LITERAL */ -#line 1092 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 134: +#line 1092 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2747 "tars.tab.cpp" +#line 2825 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 135: /* keyword: TARS_CONST */ -#line 1095 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 135: +#line 1095 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2754 "tars.tab.cpp" +#line 2832 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 136: /* keyword: TARS_ENUM */ -#line 1098 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 136: +#line 1098 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2761 "tars.tab.cpp" +#line 2839 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 137: /* keyword: TARS_UNSIGNED */ -#line 1101 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 137: +#line 1101 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2768 "tars.tab.cpp" +#line 2846 "tars.tab.cpp" /* yacc.c:1646 */ break; -#line 2772 "tars.tab.cpp" - +#line 2850 "tars.tab.cpp" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2783,23 +2860,25 @@ 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 ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); + YY_SYMBOL_PRINT ("-> $$ =", 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. */ - { - const int yylhs = yyr1[yyn] - YYNTOKENS; - const int yyi = yypgoto[yylhs] + *yyssp; - yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp - ? yytable[yyi] - : yydefgoto[yylhs]); - } + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; goto yynewstate; @@ -2810,14 +2889,50 @@ yyparse (void) yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); + yytoken = yychar == YYEMPTY ? 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 @@ -2846,10 +2961,12 @@ yyparse (void) | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: - /* Pacify compilers when the user code never invokes YYERROR and the - label yyerrorlab therefore never appears in user code. */ - if (0) - YYERROR; + + /* 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; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ @@ -2866,14 +2983,13 @@ 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 += YYSYMBOL_YYerror; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { yyn = yytable[yyn]; if (0 < yyn) @@ -2887,7 +3003,7 @@ yyparse (void) yydestruct ("Error: popping", - YY_ACCESSING_SYMBOL (yystate), yyvsp); + yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -2899,7 +3015,7 @@ yyparse (void) /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -2912,7 +3028,6 @@ yyparse (void) yyresult = 0; goto yyreturn; - /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ @@ -2920,21 +3035,16 @@ yyparse (void) yyresult = 1; goto yyreturn; - -#if !defined yyoverflow +#if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; - goto yyreturn; + /* Fall through. */ #endif - -/*-------------------------------------------------------. -| yyreturn -- parsing is finished, clean up and return. | -`-------------------------------------------------------*/ yyreturn: if (yychar != YYEMPTY) { @@ -2951,18 +3061,20 @@ yyparse (void) while (yyssp != yyss) { yydestruct ("Cleanup: popping", - YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); + yystos[*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 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" +#line 1105 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1906 */ diff --git a/tools/tarsparse/tars.lex.cpp b/tools/tarsparse/tars.lex.cpp index b624b1ba..4c5d318c 100644 --- a/tools/tarsparse/tars.lex.cpp +++ b/tools/tarsparse/tars.lex.cpp @@ -1,6 +1,6 @@ -#line 1 "tars.lex.cpp" +#line 2 "tars.lex.cpp" -#line 3 "tars.lex.cpp" +#line 4 "tars.lex.cpp" #define YY_INT_ALIGNED short int @@ -47,7 +47,6 @@ 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; @@ -156,7 +155,7 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; typedef size_t yy_size_t; #endif -extern yy_size_t yyleng; +extern int yyleng; extern FILE *yyin, *yyout; @@ -173,7 +172,7 @@ extern FILE *yyin, *yyout; */ #define YY_LESS_LINENO(n) \ do { \ - yy_size_t yyl;\ + int yyl;\ for ( yyl = n; yyl < yyleng; ++yyl )\ if ( yytext[yyl] == '\n' )\ --yylineno;\ @@ -218,7 +217,7 @@ struct yy_buffer_state /* Number of characters read into yy_ch_buf, not including EOB * characters. */ - yy_size_t yy_n_chars; + int 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 @@ -287,8 +286,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 yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */ -yy_size_t yyleng; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; /* Points to current character in buffer. */ static char *yy_c_buf_p = NULL; @@ -315,7 +314,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, yy_size_t len ); +YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len ); void *yyalloc ( yy_size_t ); void *yyrealloc ( void *, yy_size_t ); @@ -368,7 +367,7 @@ static void yynoreturn yy_fatal_error ( const char* msg ); */ #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ - yyleng = (yy_size_t) (yy_cp - yy_bp); \ + yyleng = (int) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ (yy_c_buf_p) = yy_cp; @@ -511,7 +510,7 @@ int yy_flex_debug = 0; #define YY_MORE_ADJ 0 #define YY_RESTORE_YY_MORE_OFFSET char *yytext; -#line 1 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 1 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" /** * Tencent is pleased to support the open source community by making Tars available. * @@ -527,7 +526,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 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 20 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" #include #include #include @@ -598,7 +597,7 @@ FILE *yyget_out ( void ); void yyset_out ( FILE * _out_str ); - yy_size_t yyget_leng ( void ); + int yyget_leng ( void ); char *yyget_text ( void ); @@ -667,7 +666,7 @@ static int input ( void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - yy_size_t n; \ + int n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -776,7 +775,7 @@ YY_DECL } { -#line 67 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 67 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" #line 782 "tars.lex.cpp" @@ -827,7 +826,7 @@ YY_DECL if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] ) { - yy_size_t yyl; + int yyl; for ( yyl = 0; yyl < yyleng; ++yyl ) if ( yytext[yyl] == '\n' ) @@ -848,12 +847,12 @@ YY_DECL case 1: YY_RULE_SETUP -#line 69 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 69 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { BEGIN(INCL); } YY_BREAK case 2: YY_RULE_SETUP -#line 71 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 71 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { if ( include_file_stack_ptr >= MAX_INCLUDE_DEPTH ) { @@ -886,7 +885,7 @@ YY_RULE_SETUP YY_BREAK case YY_STATE_EOF(INITIAL): case YY_STATE_EOF(INCL): -#line 101 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 101 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { --include_file_stack_ptr; if ( include_file_stack_ptr < 0 ) @@ -905,14 +904,14 @@ case YY_STATE_EOF(INCL): YY_BREAK case 3: YY_RULE_SETUP -#line 117 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 117 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { return TARS_SCOPE_DELIMITER; } YY_BREAK case 4: YY_RULE_SETUP -#line 121 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 121 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { // C++ comment bool e = false; @@ -933,7 +932,7 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 139 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 139 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { // C comment bool e = false; @@ -984,7 +983,7 @@ YY_RULE_SETUP YY_BREAK case 6: YY_RULE_SETUP -#line 187 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 187 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { StringGrammarPtr ident = new StringGrammar; ident->v = yytext; @@ -995,7 +994,7 @@ YY_RULE_SETUP case 7: /* rule 7 can match eol */ YY_RULE_SETUP -#line 194 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 194 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { StringGrammarPtr ident = new StringGrammar; ident->v = yytext; @@ -1008,7 +1007,7 @@ YY_RULE_SETUP YY_BREAK case 8: YY_RULE_SETUP -#line 204 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 204 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { StringGrammarPtr str = new StringGrammar; bool e = false; @@ -1123,7 +1122,7 @@ YY_RULE_SETUP YY_BREAK case 9: YY_RULE_SETUP -#line 316 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 316 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { errno = 0; IntergerGrammarPtr ptr = new IntergerGrammar; @@ -1148,7 +1147,7 @@ YY_RULE_SETUP YY_BREAK case 10: YY_RULE_SETUP -#line 338 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 338 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { errno = 0; FloatGrammarPtr ptr = new FloatGrammar; @@ -1183,7 +1182,7 @@ YY_RULE_SETUP case 11: /* rule 11 can match eol */ YY_RULE_SETUP -#line 369 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 369 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { if(yytext[0] == '\n') { @@ -1193,7 +1192,7 @@ YY_RULE_SETUP YY_BREAK case 12: YY_RULE_SETUP -#line 376 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 376 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" { if(yytext[0] < 32 || yytext[0] > 126) { @@ -1212,7 +1211,7 @@ YY_RULE_SETUP YY_BREAK case 13: YY_RULE_SETUP -#line 392 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 392 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" ECHO; YY_BREAK #line 1218 "tars.lex.cpp" @@ -1400,7 +1399,7 @@ static int yy_get_next_buffer (void) else { - yy_size_t num_to_read = + int num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; while ( num_to_read <= 0 ) @@ -1414,7 +1413,7 @@ static int yy_get_next_buffer (void) if ( b->yy_is_our_buffer ) { - yy_size_t new_size = b->yy_buf_size * 2; + int new_size = b->yy_buf_size * 2; if ( new_size <= 0 ) b->yy_buf_size += b->yy_buf_size / 8; @@ -1472,7 +1471,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. */ - yy_size_t new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + int 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 ) @@ -1561,7 +1560,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. */ - yy_size_t number_to_move = (yy_n_chars) + 2; + int 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 = @@ -1616,7 +1615,7 @@ static int yy_get_next_buffer (void) else { /* need more input */ - yy_size_t offset = (yy_c_buf_p) - (yytext_ptr); + int offset = (int) ((yy_c_buf_p) - (yytext_ptr)); ++(yy_c_buf_p); switch ( yy_get_next_buffer( ) ) @@ -1990,12 +1989,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, yy_size_t _yybytes_len ) +YY_BUFFER_STATE yy_scan_bytes (const char * yybytes, int _yybytes_len ) { YY_BUFFER_STATE b; char *buf; yy_size_t n; - yy_size_t i; + int i; /* Get memory for full buffer, including space for trailing EOB's. */ n = (yy_size_t) (_yybytes_len + 2); @@ -2037,7 +2036,7 @@ static void yynoreturn yy_fatal_error (const char* msg ) do \ { \ /* Undo effects of setting up yytext. */ \ - yy_size_t yyless_macro_arg = (n); \ + int yyless_macro_arg = (n); \ YY_LESS_LINENO(yyless_macro_arg);\ yytext[yyleng] = (yy_hold_char); \ (yy_c_buf_p) = yytext + yyless_macro_arg; \ @@ -2077,7 +2076,7 @@ FILE *yyget_out (void) /** Get the length of the current token. * */ -yy_size_t yyget_leng (void) +int yyget_leng (void) { return yyleng; } @@ -2230,7 +2229,7 @@ void yyfree (void * ptr ) #define YYTABLES_NAME "yytables" -#line 392 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.l" +#line 392 "/root/boat/TarsCpp/tools/tarsgrammar/tars.l" diff --git a/tools/tarsparse/tars.tab.cpp b/tools/tarsparse/tars.tab.cpp index eb0aca62..ee40db41 100644 --- a/tools/tarsparse/tars.tab.cpp +++ b/tools/tarsparse/tars.tab.cpp @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.7.6. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, - Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 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 @@ -16,7 +15,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 @@ -34,10 +33,6 @@ /* 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. @@ -45,11 +40,11 @@ define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ -/* Identify Bison output, and Bison version. */ -#define YYBISON 30706 +/* Identify Bison output. */ +#define YYBISON 1 -/* Bison version string. */ -#define YYBISON_VERSION "3.7.6" +/* Bison version. */ +#define YYBISON_VERSION "3.0.4" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -66,8 +61,8 @@ -/* First part of user prologue. */ -#line 17 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" +/* Copy the first part of user declarations. */ +#line 17 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:339 */ #include #include @@ -81,213 +76,119 @@ using namespace std; #define YYDEBUG 1 #define YYINITDEPTH 10000 -#line 85 "tars.tab.cpp" +#line 80 "tars.tab.cpp" /* yacc.c:339 */ -# 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 -# if 201103L <= __cplusplus -# define YY_NULLPTR nullptr -# else -# define YY_NULLPTR 0 -# endif +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULLPTR nullptr # else -# define YY_NULLPTR ((void*)0) +# define YY_NULLPTR 0 # endif # 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; - +/* 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 -#ifdef short -# undef short +/* Value type. */ +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef int YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define YYSTYPE_IS_DECLARED 1 #endif -/* 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. */ -#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 +extern YYSTYPE yylval; -/* 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. */ +int yyparse (void); -#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 +#endif /* !YY_YY_TARS_TAB_HPP_INCLUDED */ -#ifdef __INT_LEAST16_MAX__ -typedef __INT_LEAST16_TYPE__ yytype_int16; -#elif defined YY_STDINT_H -typedef int_least16_t yytype_int16; -#else -typedef short yytype_int16; -#endif +/* Copy the second part of user declarations. */ + +#line 165 "tars.tab.cpp" /* yacc.c:358 */ -/* 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 +#ifdef short +# undef short #endif -#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 +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; #else -typedef short yytype_uint8; +typedef signed char yytype_int8; #endif -#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; +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; #else -typedef int yytype_uint16; +typedef unsigned short 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 +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; #endif #ifndef YYSIZE_T @@ -295,28 +196,15 @@ typedef int yytype_uint16; # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t -# elif defined __STDC_VERSION__ && 199901 <= __STDC_VERSION__ +# elif ! defined YYSIZE_T # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else -# define YYSIZE_T unsigned +# define YYSIZE_T unsigned int # endif #endif -#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; +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS @@ -330,37 +218,47 @@ typedef int yy_state_fast_t; # endif #endif - -#ifndef YY_ATTRIBUTE_PURE -# if defined __GNUC__ && 2 < __GNUC__ + (96 <= __GNUC_MINOR__) -# define YY_ATTRIBUTE_PURE __attribute__ ((__pure__)) +#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_PURE +# define YY_ATTRIBUTE(Spec) /* empty */ # endif #endif +#ifndef YY_ATTRIBUTE_PURE +# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#endif + #ifndef YY_ATTRIBUTE_UNUSED -# if defined __GNUC__ && 2 < __GNUC__ + (7 <= __GNUC_MINOR__) -# define YY_ATTRIBUTE_UNUSED __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) # else -# define YY_ATTRIBUTE_UNUSED +# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YY_USE(E) ((void) (E)) +# define YYUSE(E) ((void) (E)) #else -# define YY_USE(E) /* empty */ +# define YYUSE(E) /* empty */ #endif -#if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +#if defined __GNUC__ && 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 @@ -373,22 +271,8 @@ typedef int yy_state_fast_t; # 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 - -#define YY_ASSERT(E) ((void) (0 && (E))) - -#if !defined yyoverflow +#if ! defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ @@ -453,7 +337,8 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif -#endif /* !defined yyoverflow */ +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + #if (! defined yyoverflow \ && (! defined __cplusplus \ @@ -462,17 +347,17 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ /* A type that is properly aligned for any stack member. */ union yyalloc { - yy_state_t yyss_alloc; + yytype_int16 yyss_alloc; YYSTYPE yyvs_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (YYSIZEOF (union yyalloc) - 1) +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ - ((N) * (YYSIZEOF (yy_state_t) + YYSIZEOF (YYSTYPE)) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) # define YYCOPY_NEEDED 1 @@ -485,11 +370,11 @@ union yyalloc # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ - YYPTRDIFF_T yynewbytes; \ + YYSIZE_T yynewbytes; \ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * YYSIZEOF (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / YYSIZEOF (*yyptr); \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ } \ while (0) @@ -501,12 +386,12 @@ union yyalloc # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(Dst, Src, Count) \ - __builtin_memcpy (Dst, Src, YY_CAST (YYSIZE_T, (Count)) * sizeof (*(Src))) + __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) # else # define YYCOPY(Dst, Src, Count) \ do \ { \ - YYPTRDIFF_T yyi; \ + YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (Dst)[yyi] = (Src)[yyi]; \ } \ @@ -529,20 +414,17 @@ union yyalloc /* YYNSTATES -- Number of states. */ #define YYNSTATES 199 -/* YYMAXUTOK -- Last valid token kind. */ +/* YYTRANSLATE[YYX] -- Symbol number corresponding to YYX as returned + by yylex, with out-of-bounds checking. */ +#define YYUNDEFTOK 2 #define YYMAXUTOK 288 - -/* 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) +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM - as returned by yylex. */ -static const yytype_int8 yytranslate[] = + as returned by yylex, without out-of-bounds checking. */ +static const yytype_uint8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, @@ -577,7 +459,7 @@ static const yytype_int8 yytranslate[] = #if YYDEBUG /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ -static const yytype_int16 yyrline[] = +static const yytype_uint16 yyrline[] = { 0, 68, 68, 75, 74, 79, 78, 83, 88, 95, 99, 103, 107, 110, 114, 124, 123, 146, 159, 170, @@ -596,48 +478,35 @@ static const yytype_int16 yyrline[] = }; #endif -/** 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; - +#if YYDEBUG || YYERROR_VERBOSE || 0 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { - "\"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 + "$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 }; - -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_int16 yytoknum[] = +static const yytype_uint16 yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, @@ -645,16 +514,16 @@ static const yytype_int16 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(Yyn) \ - ((Yyn) == YYPACT_NINF) +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-146))) -#define YYTABLE_NINF (-113) +#define YYTABLE_NINF -113 -#define yytable_value_is_error(Yyn) \ +#define yytable_value_is_error(Yytable_value) \ 0 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing @@ -721,9 +590,9 @@ static const yytype_int16 yypgoto[] = }; /* YYDEFGOTO[NTERM-NUM]. */ -static const yytype_uint8 yydefgoto[] = +static const yytype_int16 yydefgoto[] = { - 0, 8, 9, 76, 80, 10, 11, 77, 12, 123, + -1, 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, @@ -857,7 +726,7 @@ static const yytype_int16 yycheck[] = /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ -static const yytype_int8 yystos[] = +static const yytype_uint8 yystos[] = { 0, 1, 4, 15, 16, 20, 30, 31, 47, 48, 51, 52, 54, 57, 59, 62, 64, 73, 75, 80, @@ -882,7 +751,7 @@ static const yytype_int8 yystos[] = }; /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const yytype_int8 yyr1[] = +static const yytype_uint8 yyr1[] = { 0, 46, 47, 49, 48, 50, 48, 48, 48, 51, 51, 51, 51, 51, 51, 53, 52, 54, 54, 55, @@ -901,7 +770,7 @@ static const yytype_int8 yyr1[] = }; /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */ -static const yytype_int8 yyr2[] = +static const yytype_uint8 yyr2[] = { 0, 2, 1, 0, 4, 0, 4, 1, 0, 1, 1, 1, 1, 1, 1, 0, 5, 2, 2, 3, @@ -920,10 +789,10 @@ static const yytype_int8 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 @@ -932,26 +801,27 @@ enum { YYENOMEM = -2 }; #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) - -/* Backward compatibility with an undocumented macro. - Use YYerror or YYUNDEF. */ -#define YYERRCODE YYUNDEF +#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 + /* Enable debugging if requested. */ @@ -969,58 +839,54 @@ 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, Kind, Value, Location) \ +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Kind, Value); \ + Type, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) -/*-----------------------------------. -| Print this symbol's value on YYO. | -`-----------------------------------*/ +/*----------------------------------------. +| Print this symbol's value on YYOUTPUT. | +`----------------------------------------*/ static void -yy_symbol_value_print (FILE *yyo, - yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) { - FILE *yyoutput = yyo; - YY_USE (yyoutput); + FILE *yyo = yyoutput; + YYUSE (yyo); if (!yyvaluep) return; # ifdef YYPRINT - if (yykind < YYNTOKENS) - YYPRINT (yyo, yytoknum[yykind], *yyvaluep); + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); # endif - YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YY_USE (yykind); - YY_IGNORE_MAYBE_UNINITIALIZED_END + YYUSE (yytype); } -/*---------------------------. -| Print this symbol on YYO. | -`---------------------------*/ +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ static void -yy_symbol_print (FILE *yyo, - yysymbol_kind_t yykind, YYSTYPE const * const yyvaluep) +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) { - YYFPRINTF (yyo, "%s %s (", - yykind < YYNTOKENS ? "token" : "nterm", yysymbol_name (yykind)); + YYFPRINTF (yyoutput, "%s %s (", + yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); - yy_symbol_value_print (yyo, yykind, yyvaluep); - YYFPRINTF (yyo, ")"); + yy_symbol_value_print (yyoutput, yytype, yyvaluep); + YYFPRINTF (yyoutput, ")"); } /*------------------------------------------------------------------. @@ -1029,7 +895,7 @@ yy_symbol_print (FILE *yyo, `------------------------------------------------------------------*/ static void -yy_stack_print (yy_state_t *yybottom, yy_state_t *yytop) +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) @@ -1052,21 +918,21 @@ do { \ `------------------------------------------------*/ static void -yy_reduce_print (yy_state_t *yyssp, YYSTYPE *yyvsp, - int yyrule) +yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule) { - int yylno = yyrline[yyrule]; + unsigned long int yylno = yyrline[yyrule]; int yynrhs = yyr2[yyrule]; int yyi; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %d):\n", + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, - YY_ACCESSING_SYMBOL (+yyssp[yyi + 1 - yynrhs]), - &yyvsp[(yyi + 1) - (yynrhs)]); + yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)]) + ); YYFPRINTF (stderr, "\n"); } } @@ -1081,8 +947,8 @@ do { \ multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ -# define YYDPRINTF(Args) ((void) 0) -# define YY_SYMBOL_PRINT(Title, Kind, Value, Location) +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ @@ -1105,30 +971,249 @@ 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, - yysymbol_kind_t yykind, YYSTYPE *yyvaluep) +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) { - YY_USE (yyvaluep); + YYUSE (yyvaluep); if (!yymsg) yymsg = "Deleting"; - YY_SYMBOL_PRINT (yymsg, yykind, yyvaluep, yylocationp); + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN - YY_USE (yykind); + YYUSE (yytype); YY_IGNORE_MAYBE_UNINITIALIZED_END } -/* Lookahead token kind. */ + + +/* The lookahead symbol. */ int yychar; /* The semantic value of the lookahead symbol. */ @@ -1137,8 +1222,6 @@ YYSTYPE yylval; int yynerrs; - - /*----------. | yyparse. | `----------*/ @@ -1146,36 +1229,43 @@ int yynerrs; int yyparse (void) { - yy_state_fast_t yystate = 0; + int yystate; /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus = 0; + int yyerrstatus; - /* Refer to the stacks through separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ + /* The stacks and their tools: + 'yyss': related to states. + 'yyvs': related to semantic values. - /* Their size. */ - YYPTRDIFF_T yystacksize = YYINITDEPTH; + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ - /* The state stack: array, bottom, top. */ - yy_state_t yyssa[YYINITDEPTH]; - yy_state_t *yyss = yyssa; - yy_state_t *yyssp = yyss; + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; - /* The semantic value stack: array, bottom, top. */ + /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs = yyvsa; - YYSTYPE *yyvsp = yyvs; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + YYSIZE_T yystacksize; int yyn; - /* The return value of yyparse. */ int yyresult; - /* Lookahead symbol kind. */ - yysymbol_kind_t yytoken = YYSYMBOL_YYEMPTY; + /* Lookahead token as an internal (translated) token number. */ + int yytoken = 0; /* 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)) @@ -1183,60 +1273,58 @@ 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 -- 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); + yysetstate: + *yyssp = yystate; 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. */ - YYPTRDIFF_T yysize = yyssp - yyss + 1; + YYSIZE_T yysize = yyssp - yyss + 1; -# if defined yyoverflow +#ifdef 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 * YYSIZEOF (*yyssp), - &yyvs1, yysize * YYSIZEOF (*yyvsp), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); + yyss = yyss1; yyvs = yyvs1; } -# else /* defined YYSTACK_RELOCATE */ +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; @@ -1245,10 +1333,9 @@ yyparse (void) yystacksize = YYMAXDEPTH; { - yy_state_t *yyss1 = yyss; + yytype_int16 *yyss1 = yyss; union yyalloc *yyptr = - YY_CAST (union yyalloc *, - YYSTACK_ALLOC (YY_CAST (YYSIZE_T, YYSTACK_BYTES (yystacksize)))); + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); @@ -1258,30 +1345,30 @@ yyparse (void) YYSTACK_FREE (yyss1); } # endif +#endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; - YY_IGNORE_USELESS_CAST_BEGIN - YYDPRINTF ((stderr, "Stack size increased to %ld\n", - YY_CAST (long, yystacksize))); - YY_IGNORE_USELESS_CAST_END + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) YYABORT; } -#endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */ + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); 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. */ @@ -1292,29 +1379,18 @@ yyparse (void) /* Not known => get a lookahead token if don't already have one. */ - /* YYCHAR is either empty, or end-of-input, or a valid lookahead. */ + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { - YYDPRINTF ((stderr, "Reading a token\n")); + YYDPRINTF ((stderr, "Reading a token: ")); yychar = yylex (); } if (yychar <= YYEOF) { - yychar = YYEOF; - yytoken = YYSYMBOL_YYEOF; + yychar = yytoken = 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); @@ -1342,13 +1418,15 @@ 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; @@ -1363,7 +1441,7 @@ yyparse (void) /*-----------------------------. -| yyreduce -- do a reduction. | +| yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ @@ -1383,238 +1461,238 @@ yyparse (void) YY_REDUCE_PRINT (yyn); switch (yyn) { - case 3: /* $@1: %empty */ -#line 75 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 3: +#line 75 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1391 "tars.tab.cpp" +#line 1469 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 5: /* $@2: %empty */ -#line 79 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 5: +#line 79 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { yyerrok; } -#line 1399 "tars.tab.cpp" +#line 1477 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 7: /* definitions: definition */ -#line 84 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 7: +#line 84 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("`;' missing after definition"); } -#line 1407 "tars.tab.cpp" +#line 1485 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 8: /* definitions: %empty */ -#line 88 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 8: +#line 88 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1414 "tars.tab.cpp" +#line 1492 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 9: /* definition: namespace_def */ -#line 96 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - assert(yyvsp[0] == 0 || NamespacePtr::dynamicCast(yyvsp[0])); + case 9: +#line 96 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + assert((yyvsp[0]) == 0 || NamespacePtr::dynamicCast((yyvsp[0]))); } -#line 1422 "tars.tab.cpp" +#line 1500 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 10: /* definition: interface_def */ -#line 100 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - assert(yyvsp[0] == 0 || InterfacePtr::dynamicCast(yyvsp[0])); + case 10: +#line 100 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + assert((yyvsp[0]) == 0 || InterfacePtr::dynamicCast((yyvsp[0]))); } -#line 1430 "tars.tab.cpp" +#line 1508 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 11: /* definition: struct_def */ -#line 104 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - assert(yyvsp[0] == 0 || StructPtr::dynamicCast(yyvsp[0])); + case 11: +#line 104 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + assert((yyvsp[0]) == 0 || StructPtr::dynamicCast((yyvsp[0]))); } -#line 1438 "tars.tab.cpp" +#line 1516 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 12: /* definition: key_def */ -#line 108 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 12: +#line 108 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1445 "tars.tab.cpp" +#line 1523 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 13: /* definition: enum_def */ -#line 111 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - assert(yyvsp[0] == 0 || EnumPtr::dynamicCast(yyvsp[0])); + case 13: +#line 111 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + assert((yyvsp[0]) == 0 || EnumPtr::dynamicCast((yyvsp[0]))); } -#line 1453 "tars.tab.cpp" +#line 1531 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 14: /* definition: const_def */ -#line 115 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - assert(yyvsp[0] == 0 || ConstPtr::dynamicCast(yyvsp[0])); + case 14: +#line 115 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + assert((yyvsp[0]) == 0 || ConstPtr::dynamicCast((yyvsp[0]))); } -#line 1461 "tars.tab.cpp" +#line 1539 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 15: /* @3: %empty */ -#line 124 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = yyvsp[0]; + case 15: +#line 124 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = (yyvsp[0]); } -#line 1469 "tars.tab.cpp" +#line 1547 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 16: /* enum_def: enum_id @3 '{' enumerator_list '}' */ -#line 128 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - if(yyvsp[-2]) + case 16: +#line 128 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + if((yyvsp[-2])) { g_parse->popContainer(); - yyval = yyvsp[-2]; + (yyval) = (yyvsp[-2]); } else { - yyval = 0; + (yyval) = 0; } - yyval = yyvsp[-3]; + (yyval) = (yyvsp[-3]); } -#line 1487 "tars.tab.cpp" +#line 1565 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 17: /* enum_id: TARS_ENUM TARS_IDENTIFIER */ -#line 147 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 17: +#line 147 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 1504 "tars.tab.cpp" +#line 1582 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 18: /* enum_id: TARS_ENUM keyword */ -#line 160 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 18: +#line 160 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 1514 "tars.tab.cpp" +#line 1592 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 19: /* enumerator_list: enumerator ',' enumerator_list */ -#line 171 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = yyvsp[-1]; + case 19: +#line 171 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = (yyvsp[-1]); } -#line 1522 "tars.tab.cpp" +#line 1600 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 20: /* enumerator_list: enumerator */ -#line 175 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 20: +#line 175 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1529 "tars.tab.cpp" +#line 1607 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 21: /* enumerator: TARS_IDENTIFIER */ -#line 183 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 21: +#line 183 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 1544 "tars.tab.cpp" +#line 1622 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 22: /* enumerator: keyword */ -#line 194 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 22: +#line 194 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); g_parse->error("keyword `" + ident->v + "' cannot be used as enumerator"); } -#line 1553 "tars.tab.cpp" +#line 1631 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 23: /* enumerator: TARS_IDENTIFIER '=' const_initializer */ -#line 199 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 23: +#line 199 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 1570 "tars.tab.cpp" +#line 1648 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 24: /* enumerator: %empty */ -#line 212 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 24: +#line 212 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1577 "tars.tab.cpp" +#line 1655 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 25: /* @4: %empty */ -#line 220 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 25: +#line 220 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 1596 "tars.tab.cpp" +#line 1674 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 26: /* namespace_def: TARS_NAMESPACE TARS_IDENTIFIER @4 '{' definitions '}' */ -#line 235 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - if(yyvsp[-3]) + case 26: +#line 235 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + if((yyvsp[-3])) { g_parse->popContainer(); - yyval = yyvsp[-3]; + (yyval) = (yyvsp[-3]); } else { - yyval = 0; + (yyval) = 0; } } -#line 1612 "tars.tab.cpp" +#line 1690 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 27: /* $@5: %empty */ -#line 253 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-1]); + case 27: +#line 253 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[-1])); StructPtr sp = StructPtr::dynamicCast(g_parse->findUserType(ident->v)); if(!sp) { @@ -1623,20 +1701,20 @@ yyparse (void) g_parse->setKeyStruct(sp); } -#line 1627 "tars.tab.cpp" +#line 1705 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 28: /* key_def: TARS_KEY '[' scoped_name ',' $@5 key_members ']' */ -#line 264 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 28: +#line 264 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1634 "tars.tab.cpp" +#line 1712 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 29: /* key_members: TARS_IDENTIFIER */ -#line 272 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 29: +#line 272 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); StructPtr np = g_parse->getKeyStruct(); if(np) { @@ -1644,16 +1722,16 @@ yyparse (void) } else { - yyval = 0; + (yyval) = 0; } } -#line 1651 "tars.tab.cpp" +#line 1729 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 30: /* key_members: key_members ',' TARS_IDENTIFIER */ -#line 285 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 30: +#line 285 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); StructPtr np = g_parse->getKeyStruct(); if(np) { @@ -1661,16 +1739,16 @@ yyparse (void) } else { - yyval = 0; + (yyval) = 0; } } -#line 1668 "tars.tab.cpp" +#line 1746 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 31: /* @6: %empty */ -#line 304 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 31: +#line 304 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); NamespacePtr c = NamespacePtr::dynamicCast(g_parse->currentContainer()); @@ -1678,100 +1756,100 @@ yyparse (void) if(cl) { g_parse->pushContainer(cl); - yyval = GrammarBasePtr::dynamicCast(cl); + (yyval) = GrammarBasePtr::dynamicCast(cl); } else { - yyval = 0; + (yyval) = 0; } } -#line 1689 "tars.tab.cpp" +#line 1767 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 32: /* interface_def: interface_id @6 '{' interface_exports '}' */ -#line 321 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - if(yyvsp[-3]) + case 32: +#line 321 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + if((yyvsp[-3])) { g_parse->popContainer(); - yyval = GrammarBasePtr::dynamicCast(yyvsp[-3]); + (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-3])); } else { - yyval = 0; + (yyval) = 0; } } -#line 1705 "tars.tab.cpp" +#line 1783 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 33: /* interface_id: TARS_INTERFACE TARS_IDENTIFIER */ -#line 338 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = yyvsp[0]; + case 33: +#line 338 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = (yyvsp[0]); } -#line 1713 "tars.tab.cpp" +#line 1791 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 34: /* interface_id: TARS_INTERFACE keyword */ -#line 342 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 34: +#line 342 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 1723 "tars.tab.cpp" +#line 1801 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 35: /* interface_exports: interface_export ';' interface_exports */ -#line 353 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 35: +#line 353 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1730 "tars.tab.cpp" +#line 1808 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 36: /* interface_exports: error ';' interface_exports */ -#line 356 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 36: +#line 356 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1737 "tars.tab.cpp" +#line 1815 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 37: /* interface_exports: interface_export */ -#line 359 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 37: +#line 359 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("`;' missing after definition"); } -#line 1745 "tars.tab.cpp" +#line 1823 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 38: /* interface_exports: %empty */ -#line 363 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 38: +#line 363 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1752 "tars.tab.cpp" +#line 1830 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 40: /* operation: operation_preamble parameters ')' */ -#line 377 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - if(yyvsp[-2]) + case 40: +#line 377 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + if((yyvsp[-2])) { g_parse->popContainer(); - yyval = GrammarBasePtr::dynamicCast(yyvsp[-2]); + (yyval) = GrammarBasePtr::dynamicCast((yyvsp[-2])); } else { - yyval = 0; + (yyval) = 0; } } -#line 1768 "tars.tab.cpp" +#line 1846 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 41: /* operation_preamble: return_type TARS_OP */ -#line 394 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypePtr returnType = TypePtr::dynamicCast(yyvsp[-1]); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + 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])); string name = ident->v; InterfacePtr cl = InterfacePtr::dynamicCast(g_parse->currentContainer()); if(cl) @@ -1780,40 +1858,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 1796 "tars.tab.cpp" +#line 1874 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 43: /* return_type: TARS_VOID */ -#line 424 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = 0; + case 43: +#line 424 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = 0; } -#line 1804 "tars.tab.cpp" +#line 1882 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 44: /* parameters: %empty */ -#line 434 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 44: +#line 434 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 1811 "tars.tab.cpp" +#line 1889 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 45: /* parameters: type_id */ -#line 437 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + case 45: +#line 437 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1822,13 +1900,13 @@ yyparse (void) op->createParamDecl(tsp, false, false); } } -#line 1826 "tars.tab.cpp" +#line 1904 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 46: /* parameters: parameters ',' type_id */ -#line 448 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + case 46: +#line 448 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + TypeIdPtr tsp = TypeIdPtr::dynamicCast((yyvsp[0])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1837,14 +1915,14 @@ yyparse (void) op->createParamDecl(tsp, false, false); } } -#line 1841 "tars.tab.cpp" +#line 1919 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 47: /* parameters: out_qualifier type_id */ -#line 459 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + 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])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1853,14 +1931,14 @@ yyparse (void) op->createParamDecl(tsp, isOutParam->v, false); } } -#line 1857 "tars.tab.cpp" +#line 1935 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 48: /* parameters: parameters ',' out_qualifier type_id */ -#line 471 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - BoolGrammarPtr isOutParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + 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])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1869,14 +1947,14 @@ yyparse (void) op->createParamDecl(tsp, isOutParam->v, false); } } -#line 1873 "tars.tab.cpp" +#line 1951 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 49: /* parameters: routekey_qualifier type_id */ -#line 483 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + 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])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1885,14 +1963,14 @@ yyparse (void) op->createParamDecl(tsp, false, isRouteKeyParam->v); } } -#line 1889 "tars.tab.cpp" +#line 1967 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 50: /* parameters: parameters ',' routekey_qualifier type_id */ -#line 495 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - BoolGrammarPtr isRouteKeyParam = BoolGrammarPtr::dynamicCast(yyvsp[-1]); - TypeIdPtr tsp = TypeIdPtr::dynamicCast(yyvsp[0]); + 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])); OperationPtr op = OperationPtr::dynamicCast(g_parse->currentContainer()); assert(op); @@ -1901,49 +1979,49 @@ yyparse (void) op->createParamDecl(tsp, false, isRouteKeyParam->v); } } -#line 1905 "tars.tab.cpp" +#line 1983 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 51: /* parameters: out_qualifier */ -#line 507 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 51: +#line 507 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("'out' must be defined with a type"); } -#line 1913 "tars.tab.cpp" +#line 1991 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 52: /* parameters: routekey_qualifier */ -#line 511 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 52: +#line 511 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("'routekey' must be defined with a type"); } -#line 1921 "tars.tab.cpp" +#line 1999 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 53: /* routekey_qualifier: TARS_ROUTE_KEY */ -#line 520 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 53: +#line 520 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { BoolGrammarPtr routekey = new BoolGrammar; routekey->v = true; - yyval = GrammarBasePtr::dynamicCast(routekey); + (yyval) = GrammarBasePtr::dynamicCast(routekey); } -#line 1931 "tars.tab.cpp" +#line 2009 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 54: /* out_qualifier: TARS_OUT */ -#line 531 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 54: +#line 531 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { BoolGrammarPtr out = new BoolGrammar; out->v = true; - yyval = GrammarBasePtr::dynamicCast(out); + (yyval) = GrammarBasePtr::dynamicCast(out); } -#line 1941 "tars.tab.cpp" +#line 2019 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 55: /* @7: %empty */ -#line 542 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 55: +#line 542 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); NamespacePtr np = NamespacePtr::dynamicCast(g_parse->currentContainer()); if(np) { @@ -1951,11 +2029,11 @@ yyparse (void) if(sp) { g_parse->pushContainer(sp); - yyval = GrammarBasePtr::dynamicCast(sp); + (yyval) = GrammarBasePtr::dynamicCast(sp); } else { - yyval = 0; + (yyval) = 0; } } else @@ -1963,280 +2041,280 @@ yyparse (void) g_parse->error("struct '" + ident->v + "' must definition in namespace"); } } -#line 1967 "tars.tab.cpp" +#line 2045 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 56: /* struct_def: struct_id @7 '{' struct_exports '}' */ -#line 564 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - if(yyvsp[-3]) + case 56: +#line 564 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 1986 "tars.tab.cpp" +#line 2064 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 57: /* struct_id: TARS_STRUCT TARS_IDENTIFIER */ -#line 584 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = yyvsp[0]; + case 57: +#line 584 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = (yyvsp[0]); } -#line 1994 "tars.tab.cpp" +#line 2072 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 58: /* struct_id: TARS_STRUCT keyword */ -#line 588 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 58: +#line 588 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); g_parse->error("keyword `" + ident->v + "' cannot be used as struct name"); } -#line 2004 "tars.tab.cpp" +#line 2082 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 59: /* struct_id: TARS_STRUCT error */ -#line 594 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 59: +#line 594 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("abstract declarator '' used as declaration"); } -#line 2012 "tars.tab.cpp" +#line 2090 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 60: /* struct_exports: data_member ';' struct_exports */ -#line 603 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 60: +#line 603 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2020 "tars.tab.cpp" +#line 2098 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 61: /* struct_exports: data_member */ -#line 607 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 61: +#line 607 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("';' missing after definition"); } -#line 2028 "tars.tab.cpp" +#line 2106 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 62: /* struct_exports: %empty */ -#line 611 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 62: +#line 611 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2035 "tars.tab.cpp" +#line 2113 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 63: /* data_member: struct_type_id */ -#line 621 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); + case 63: +#line 621 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); } -#line 2043 "tars.tab.cpp" +#line 2121 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 64: /* struct_type_id: TARS_CONST_INTEGER TARS_REQUIRE type_id */ -#line 630 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 64: +#line 630 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 2065 "tars.tab.cpp" +#line 2143 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 65: /* struct_type_id: TARS_CONST_INTEGER TARS_REQUIRE type_id '=' const_initializer */ -#line 648 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 65: +#line 648 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 2091 "tars.tab.cpp" +#line 2169 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 66: /* struct_type_id: TARS_CONST_INTEGER TARS_OPTIONAL type_id '=' const_initializer */ -#line 670 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 66: +#line 670 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 2117 "tars.tab.cpp" +#line 2195 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 67: /* struct_type_id: TARS_CONST_INTEGER TARS_OPTIONAL type_id */ -#line 692 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 67: +#line 692 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 2138 "tars.tab.cpp" +#line 2216 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 68: /* struct_type_id: TARS_REQUIRE type_id */ -#line 709 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 68: +#line 709 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("struct member need 'tag'"); } -#line 2146 "tars.tab.cpp" +#line 2224 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 69: /* struct_type_id: TARS_OPTIONAL type_id */ -#line 713 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 69: +#line 713 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("struct member need 'tag'"); } -#line 2154 "tars.tab.cpp" +#line 2232 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 70: /* struct_type_id: TARS_CONST_INTEGER type_id */ -#line 717 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 70: +#line 717 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("struct member need 'require' or 'optional'"); } -#line 2162 "tars.tab.cpp" +#line 2240 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 71: /* struct_type_id: type_id */ -#line 721 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 71: +#line 721 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("struct member need 'tag' or 'require' or 'optional'"); } -#line 2170 "tars.tab.cpp" +#line 2248 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 72: /* const_initializer: TARS_CONST_INTEGER */ -#line 730 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - IntergerGrammarPtr intVal = IntergerGrammarPtr::dynamicCast(yyvsp[0]); + case 72: +#line 730 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 2184 "tars.tab.cpp" +#line 2262 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 73: /* const_initializer: TARS_CONST_FLOAT */ -#line 740 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - FloatGrammarPtr floatVal = FloatGrammarPtr::dynamicCast(yyvsp[0]); + case 73: +#line 740 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 2198 "tars.tab.cpp" +#line 2276 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 74: /* const_initializer: TARS_STRING_LITERAL */ -#line 750 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 74: +#line 750 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::STRING; c->v = ident->v; - yyval = c; + (yyval) = c; } -#line 2210 "tars.tab.cpp" +#line 2288 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 75: /* const_initializer: TARS_FALSE */ -#line 758 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 75: +#line 758 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::BOOL; c->v = ident->v; - yyval = c; + (yyval) = c; } -#line 2222 "tars.tab.cpp" +#line 2300 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 76: /* const_initializer: TARS_TRUE */ -#line 766 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 76: +#line 766 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::BOOL; c->v = ident->v; - yyval = c; + (yyval) = c; } -#line 2234 "tars.tab.cpp" +#line 2312 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 77: /* const_initializer: TARS_IDENTIFIER */ -#line 774 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 77: +#line 774 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); if (g_parse->checkEnum(ident->v) == false) { @@ -2245,17 +2323,17 @@ yyparse (void) ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::ENUM; c->v = ident->v; - yyval = c; + (yyval) = c; } -#line 2251 "tars.tab.cpp" +#line 2329 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 78: /* const_initializer: scoped_name TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ -#line 787 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 78: +#line 787 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { - 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) { @@ -2264,512 +2342,511 @@ yyparse (void) ConstGrammarPtr c = new ConstGrammar(); c->t = ConstGrammar::ENUM; c->v = scoped->v + "::" + ident->v; - yyval = c; + (yyval) = c; } -#line 2270 "tars.tab.cpp" +#line 2348 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 79: /* const_def: TARS_CONST type_id '=' const_initializer */ -#line 807 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 79: +#line 807 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { 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 2287 "tars.tab.cpp" +#line 2365 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 80: /* type_id: type TARS_IDENTIFIER */ -#line 825 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypePtr type = TypePtr::dynamicCast(yyvsp[-1]); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + 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])); TypeIdPtr typeIdPtr = new TypeId(type, ident->v); - yyval = GrammarBasePtr::dynamicCast(typeIdPtr); + (yyval) = GrammarBasePtr::dynamicCast(typeIdPtr); } -#line 2300 "tars.tab.cpp" +#line 2378 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 81: /* type_id: type TARS_IDENTIFIER '[' TARS_CONST_INTEGER ']' */ -#line 834 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypePtr type = g_parse->createVector(TypePtr::dynamicCast(yyvsp[-4])); - IntergerGrammarPtr iPtrSize = IntergerGrammarPtr::dynamicCast(yyvsp[-1]); + 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])); 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 2314 "tars.tab.cpp" +#line 2392 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 82: /* type_id: type '*' TARS_IDENTIFIER */ -#line 844 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypePtr type = g_parse->createVector(TypePtr::dynamicCast(yyvsp[-2])); + case 82: +#line 844 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 2328 "tars.tab.cpp" +#line 2406 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 83: /* type_id: type TARS_IDENTIFIER ':' TARS_CONST_INTEGER */ -#line 854 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - TypePtr type = TypePtr::dynamicCast(yyvsp[-3]); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[-2]); + 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])); 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 2341 "tars.tab.cpp" +#line 2419 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 84: /* type_id: type keyword */ -#line 863 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 84: +#line 863 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); g_parse->error("keyword `" + ident->v + "' cannot be used as data member name"); } -#line 2350 "tars.tab.cpp" +#line 2428 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 85: /* type_id: type */ -#line 868 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 85: +#line 868 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("missing data member name"); } -#line 2358 "tars.tab.cpp" +#line 2436 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 86: /* type_id: error */ -#line 872 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 86: +#line 872 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("unkown type"); } -#line 2366 "tars.tab.cpp" +#line 2444 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 87: /* type: type_no ':' TARS_CONST_INTEGER */ -#line 881 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 87: +#line 881 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { - 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 2379 "tars.tab.cpp" +#line 2457 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 88: /* type: type_no */ -#line 890 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = yyvsp[0]; + case 88: +#line 890 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = (yyvsp[0]); } -#line 2387 "tars.tab.cpp" +#line 2465 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 89: /* type: type_no ':' error */ -#line 894 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 89: +#line 894 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("array missing size"); } -#line 2395 "tars.tab.cpp" +#line 2473 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 90: /* type_no: TARS_BOOL */ -#line 903 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindBool); + case 90: +#line 903 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindBool); } -#line 2403 "tars.tab.cpp" +#line 2481 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 91: /* type_no: TARS_BYTE */ -#line 907 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindByte); + case 91: +#line 907 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindByte); } -#line 2411 "tars.tab.cpp" +#line 2489 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 92: /* type_no: TARS_UNSIGNED TARS_BYTE */ -#line 911 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindShort,true); + case 92: +#line 911 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindShort,true); } -#line 2419 "tars.tab.cpp" +#line 2497 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 93: /* type_no: TARS_SHORT */ -#line 915 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindShort); + case 93: +#line 915 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindShort); } -#line 2427 "tars.tab.cpp" +#line 2505 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 94: /* type_no: TARS_UNSIGNED TARS_SHORT */ -#line 919 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindInt,true); + case 94: +#line 919 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindInt,true); } -#line 2435 "tars.tab.cpp" +#line 2513 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 95: /* type_no: TARS_INT */ -#line 923 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindInt); + case 95: +#line 923 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindInt); } -#line 2443 "tars.tab.cpp" +#line 2521 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 96: /* type_no: TARS_UNSIGNED TARS_INT */ -#line 927 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindLong,true); + case 96: +#line 927 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindLong,true); } -#line 2451 "tars.tab.cpp" +#line 2529 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 97: /* type_no: TARS_LONG */ -#line 931 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindLong); + case 97: +#line 931 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindLong); } -#line 2459 "tars.tab.cpp" +#line 2537 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 98: /* type_no: TARS_FLOAT */ -#line 935 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindFloat); + case 98: +#line 935 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindFloat); } -#line 2467 "tars.tab.cpp" +#line 2545 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 99: /* type_no: TARS_DOUBLE */ -#line 939 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindDouble); + case 99: +#line 939 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindDouble); } -#line 2475 "tars.tab.cpp" +#line 2553 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 100: /* type_no: TARS_STRING */ -#line 943 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = g_parse->createBuiltin(Builtin::KindString); + case 100: +#line 943 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = g_parse->createBuiltin(Builtin::KindString); } -#line 2483 "tars.tab.cpp" +#line 2561 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 101: /* type_no: vector */ -#line 947 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); + case 101: +#line 947 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); } -#line 2491 "tars.tab.cpp" +#line 2569 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 102: /* type_no: map */ -#line 951 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = GrammarBasePtr::dynamicCast(yyvsp[0]); + case 102: +#line 951 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = GrammarBasePtr::dynamicCast((yyvsp[0])); } -#line 2499 "tars.tab.cpp" +#line 2577 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 103: /* type_no: scoped_name */ -#line 955 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 103: +#line 955 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + 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 2516 "tars.tab.cpp" +#line 2594 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 104: /* vector: TARS_VECTOR '<' type '>' */ -#line 973 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = GrammarBasePtr::dynamicCast(g_parse->createVector(TypePtr::dynamicCast(yyvsp[-1]))); + case 104: +#line 973 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + (yyval) = GrammarBasePtr::dynamicCast(g_parse->createVector(TypePtr::dynamicCast((yyvsp[-1])))); } -#line 2524 "tars.tab.cpp" +#line 2602 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 105: /* vector: TARS_VECTOR '<' error */ -#line 977 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 105: +#line 977 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("vector error"); } -#line 2532 "tars.tab.cpp" +#line 2610 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 106: /* vector: TARS_VECTOR '<' type error */ -#line 981 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 106: +#line 981 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("vector missing '>'"); } -#line 2540 "tars.tab.cpp" +#line 2618 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 107: /* vector: TARS_VECTOR error */ -#line 985 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 107: +#line 985 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("vector missing type"); } -#line 2548 "tars.tab.cpp" +#line 2626 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 108: /* map: TARS_MAP '<' type ',' type '>' */ -#line 994 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - yyval = GrammarBasePtr::dynamicCast(g_parse->createMap(TypePtr::dynamicCast(yyvsp[-3]), TypePtr::dynamicCast(yyvsp[-1]))); + 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])))); } -#line 2556 "tars.tab.cpp" +#line 2634 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 109: /* map: TARS_MAP '<' error */ -#line 998 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 109: +#line 998 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { g_parse->error("map error"); } -#line 2564 "tars.tab.cpp" +#line 2642 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 110: /* scoped_name: TARS_IDENTIFIER */ -#line 1007 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 110: +#line 1007 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2571 "tars.tab.cpp" +#line 2649 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 111: /* scoped_name: TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ -#line 1010 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + case 111: +#line 1010 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { + StringGrammarPtr ident = StringGrammarPtr::dynamicCast((yyvsp[0])); ident->v = "::" + ident->v; - yyval = GrammarBasePtr::dynamicCast(ident); + (yyval) = GrammarBasePtr::dynamicCast(ident); } -#line 2581 "tars.tab.cpp" +#line 2659 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 112: /* scoped_name: scoped_name TARS_SCOPE_DELIMITER TARS_IDENTIFIER */ -#line 1016 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ - StringGrammarPtr scoped = StringGrammarPtr::dynamicCast(yyvsp[-2]); - StringGrammarPtr ident = StringGrammarPtr::dynamicCast(yyvsp[0]); + 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])); scoped->v += "::"; scoped->v += ident->v; - yyval = GrammarBasePtr::dynamicCast(scoped); + (yyval) = GrammarBasePtr::dynamicCast(scoped); } -#line 2593 "tars.tab.cpp" +#line 2671 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 113: /* keyword: TARS_STRUCT */ -#line 1029 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 113: +#line 1029 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2600 "tars.tab.cpp" +#line 2678 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 114: /* keyword: TARS_VOID */ -#line 1032 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 114: +#line 1032 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2607 "tars.tab.cpp" +#line 2685 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 115: /* keyword: TARS_BOOL */ -#line 1035 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 115: +#line 1035 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2614 "tars.tab.cpp" +#line 2692 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 116: /* keyword: TARS_BYTE */ -#line 1038 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 116: +#line 1038 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2621 "tars.tab.cpp" +#line 2699 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 117: /* keyword: TARS_SHORT */ -#line 1041 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 117: +#line 1041 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2628 "tars.tab.cpp" +#line 2706 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 118: /* keyword: TARS_INT */ -#line 1044 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 118: +#line 1044 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2635 "tars.tab.cpp" +#line 2713 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 119: /* keyword: TARS_FLOAT */ -#line 1047 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 119: +#line 1047 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2642 "tars.tab.cpp" +#line 2720 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 120: /* keyword: TARS_DOUBLE */ -#line 1050 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 120: +#line 1050 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2649 "tars.tab.cpp" +#line 2727 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 121: /* keyword: TARS_STRING */ -#line 1053 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 121: +#line 1053 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2656 "tars.tab.cpp" +#line 2734 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 122: /* keyword: TARS_VECTOR */ -#line 1056 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 122: +#line 1056 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2663 "tars.tab.cpp" +#line 2741 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 123: /* keyword: TARS_KEY */ -#line 1059 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 123: +#line 1059 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2670 "tars.tab.cpp" +#line 2748 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 124: /* keyword: TARS_MAP */ -#line 1062 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 124: +#line 1062 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2677 "tars.tab.cpp" +#line 2755 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 125: /* keyword: TARS_NAMESPACE */ -#line 1065 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 125: +#line 1065 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2684 "tars.tab.cpp" +#line 2762 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 126: /* keyword: TARS_INTERFACE */ -#line 1068 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 126: +#line 1068 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2691 "tars.tab.cpp" +#line 2769 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 127: /* keyword: TARS_OUT */ -#line 1071 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 127: +#line 1071 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2698 "tars.tab.cpp" +#line 2776 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 128: /* keyword: TARS_REQUIRE */ -#line 1074 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 128: +#line 1074 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2705 "tars.tab.cpp" +#line 2783 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 129: /* keyword: TARS_OPTIONAL */ -#line 1077 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 129: +#line 1077 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2712 "tars.tab.cpp" +#line 2790 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 130: /* keyword: TARS_CONST_INTEGER */ -#line 1080 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 130: +#line 1080 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2719 "tars.tab.cpp" +#line 2797 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 131: /* keyword: TARS_CONST_FLOAT */ -#line 1083 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 131: +#line 1083 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2726 "tars.tab.cpp" +#line 2804 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 132: /* keyword: TARS_FALSE */ -#line 1086 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 132: +#line 1086 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2733 "tars.tab.cpp" +#line 2811 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 133: /* keyword: TARS_TRUE */ -#line 1089 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 133: +#line 1089 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2740 "tars.tab.cpp" +#line 2818 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 134: /* keyword: TARS_STRING_LITERAL */ -#line 1092 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 134: +#line 1092 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2747 "tars.tab.cpp" +#line 2825 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 135: /* keyword: TARS_CONST */ -#line 1095 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 135: +#line 1095 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2754 "tars.tab.cpp" +#line 2832 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 136: /* keyword: TARS_ENUM */ -#line 1098 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 136: +#line 1098 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2761 "tars.tab.cpp" +#line 2839 "tars.tab.cpp" /* yacc.c:1646 */ break; - case 137: /* keyword: TARS_UNSIGNED */ -#line 1101 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" -{ + case 137: +#line 1101 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1646 */ + { } -#line 2768 "tars.tab.cpp" +#line 2846 "tars.tab.cpp" /* yacc.c:1646 */ break; -#line 2772 "tars.tab.cpp" - +#line 2850 "tars.tab.cpp" /* yacc.c:1646 */ default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2783,23 +2860,25 @@ 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 ("-> $$ =", YY_CAST (yysymbol_kind_t, yyr1[yyn]), &yyval, &yyloc); + YY_SYMBOL_PRINT ("-> $$ =", 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. */ - { - const int yylhs = yyr1[yyn] - YYNTOKENS; - const int yyi = yypgoto[yylhs] + *yyssp; - yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp - ? yytable[yyi] - : yydefgoto[yylhs]); - } + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; goto yynewstate; @@ -2810,14 +2889,50 @@ yyparse (void) yyerrlab: /* Make sure we have latest lookahead translation. See comments at user semantic actions for why this is necessary. */ - yytoken = yychar == YYEMPTY ? YYSYMBOL_YYEMPTY : YYTRANSLATE (yychar); + yytoken = yychar == YYEMPTY ? 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 @@ -2846,10 +2961,12 @@ yyparse (void) | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: - /* Pacify compilers when the user code never invokes YYERROR and the - label yyerrorlab therefore never appears in user code. */ - if (0) - YYERROR; + + /* 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; /* Do not reclaim the symbols of the rule whose action triggered this YYERROR. */ @@ -2866,14 +2983,13 @@ 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 += YYSYMBOL_YYerror; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYSYMBOL_YYerror) + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { yyn = yytable[yyn]; if (0 < yyn) @@ -2887,7 +3003,7 @@ yyparse (void) yydestruct ("Error: popping", - YY_ACCESSING_SYMBOL (yystate), yyvsp); + yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -2899,7 +3015,7 @@ yyparse (void) /* Shift the error token. */ - YY_SYMBOL_PRINT ("Shifting", YY_ACCESSING_SYMBOL (yyn), yyvsp, yylsp); + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; @@ -2912,7 +3028,6 @@ yyparse (void) yyresult = 0; goto yyreturn; - /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ @@ -2920,21 +3035,16 @@ yyparse (void) yyresult = 1; goto yyreturn; - -#if !defined yyoverflow +#if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; - goto yyreturn; + /* Fall through. */ #endif - -/*-------------------------------------------------------. -| yyreturn -- parsing is finished, clean up and return. | -`-------------------------------------------------------*/ yyreturn: if (yychar != YYEMPTY) { @@ -2951,18 +3061,20 @@ yyparse (void) while (yyssp != yyss) { yydestruct ("Cleanup: popping", - YY_ACCESSING_SYMBOL (+*yyssp), yyvsp); + yystos[*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 "/Volumes/MyData/centos/TarsCpp/tools/tarsgrammar/tars.y" +#line 1105 "/root/boat/TarsCpp/tools/tarsgrammar/tars.y" /* yacc.c:1906 */ diff --git a/tools/tarsparse/tars.tab.hpp b/tools/tarsparse/tars.tab.hpp index 7a3f80ae..547e0174 100644 --- a/tools/tarsparse/tars.tab.hpp +++ b/tools/tarsparse/tars.tab.hpp @@ -1,9 +1,8 @@ -/* A Bison parser, made by GNU Bison 3.7.6. */ +/* A Bison parser, made by GNU Bison 3.0.4. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2021 Free Software Foundation, - Inc. + Copyright (C) 1984, 1989-1990, 2000-2015 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 @@ -16,7 +15,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 @@ -31,10 +30,6 @@ 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. */ @@ -45,48 +40,43 @@ extern int yydebug; #endif -/* Token kinds. */ +/* Token type. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE enum yytokentype { - 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 */ + 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 }; - typedef enum yytokentype yytoken_kind_t; #endif /* Value type. */ diff --git a/unit-test/hello_test.cpp b/unit-test/hello_test.cpp index 8fef0a6b..32d684f1 100755 --- a/unit-test/hello_test.cpp +++ b/unit-test/hello_test.cpp @@ -170,6 +170,7 @@ void ClientHelloCallback::callback_testHello(int ret, const string &r) { callback_count++; +// LOG_CONSOLE_DEBUG << "callback_count:" << callback_count << endl; if(!_prx) { ASSERT_TRUE(ret == 0); @@ -506,6 +507,7 @@ void HelloTest::checkSync(Communicator *comm, const string &adapter) HelloPrx prx = getObj(comm, adapter); int64_t start = TC_Common::now2us(); + prx->tars_ping(); string out; //发起远程调用 for (int j = 0; j < _count; ++j) { @@ -551,6 +553,8 @@ void HelloTest::checkASync(Communicator *comm, const string &adapter) prx->async_testHello(p, j, _buffer); } + TC_Common::sleep(1); + waitForFinish(callback_count, _count); ASSERT_TRUE(callback_count == _count); @@ -705,7 +709,12 @@ void HelloTest::rpcFromRegistry(Communicator *comm) ASSERT_TRUE(ret == 0); ASSERT_TRUE(out == _buffer); - //test rpc loop + //先调用几次 + ret = qPrx->testPid(out); + ret = qPrx->testPid(out); + ASSERT_TRUE(ret == 0); + + //test rpc loop int count = 10; while(count-- > 0) { @@ -755,7 +764,7 @@ void HelloTest::rpcConHashFromRegistry(Communicator *comm) for (int j = 0; j < 10; ++j) { std::string serverInfo; int ret = prx->tars_consistent_hash(TC_Thread::CURRENT_THREADID())->testConHash(serverInfo); - LOG_CONSOLE_DEBUG << "hashCode:" << TC_Thread::CURRENT_THREADID() << ", serverInfo:" << serverInfo << endl; +// LOG_CONSOLE_DEBUG << "hashCode:" << TC_Thread::CURRENT_THREADID() << ", serverInfo:" << serverInfo << endl; servInfos.emplace(serverInfo); ASSERT_TRUE(ret == 0); } diff --git a/unit-test/hello_test.h b/unit-test/hello_test.h index e8628aa4..8bc92905 100755 --- a/unit-test/hello_test.h +++ b/unit-test/hello_test.h @@ -259,6 +259,7 @@ class HelloTest : public testing::Test // comm->setProperty("asyncqueuecap", "1000000"); string obj = getObj(_conf, adapter); + LOG_CONSOLE_DEBUG << obj << endl; T prx = comm->stringToProxy(obj); prx->tars_timeout(60000); @@ -267,12 +268,34 @@ class HelloTest : public testing::Test return prx; } + int GetUsedFileDescriptorCount() + { + // 使用 shell 命令 "lsof" 获取已使用的文件句柄数量 + FILE* file = popen("lsof -p $$ | wc -l", "r"); + if (!file) { + std::cerr << "can not lsof" << std::endl; + return -1; + } + + char buffer[128]; + std::string result; + while (fgets(buffer, sizeof(buffer), file) != NULL) { + result += buffer; + } + pclose(file); + + // 解析结果并提取文件句柄数量 + int usedFileDescriptors = std::stoi(result); + return usedFileDescriptors; + } + int getFdCounts() { - //linux下才生效, 其他平台都是返回的0 - vector fds; - TC_File::listDirectory("/proc/" + TC_Common::tostr(getpid()) + "/fd", fds, false); - return fds.size(); +#if TARGET_PLATFORM_WINDOWS + return 0; +#else + return GetUsedFileDescriptorCount(); +#endif } int getSocketFd(int iSocketType = SOCK_DGRAM, int iDomain = AF_INET) diff --git a/unit-test/rpc/test_async_rpc.cpp b/unit-test/rpc/test_async_rpc.cpp index 208986fb..0ddf7662 100755 --- a/unit-test/rpc/test_async_rpc.cpp +++ b/unit-test/rpc/test_async_rpc.cpp @@ -1,13 +1,26 @@  #include "hello_test.h" +TEST_F(HelloTest, test) +{ + { + HelloServer server; + startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) 1); + + stopServer(server); + } +} + + TEST_F(HelloTest, rpcASyncGlobalCommunicator) { - shared_ptr c = getCommunicator(); + { + shared_ptr c = getCommunicator(); - transGlobalCommunicator([&](Communicator *comm){ - checkASync(comm); - }, c.get()); + transGlobalCommunicator([&](Communicator *comm) { + checkASync(comm); + }, c.get()); + } } diff --git a/unit-test/rpc/test_close.cpp b/unit-test/rpc/test_close.cpp new file mode 100755 index 00000000..515ec80d --- /dev/null +++ b/unit-test/rpc/test_close.cpp @@ -0,0 +1,58 @@ + +#include "hello_test.h" +#include "servant/CommunicatorEpoll.h" +#include "servant/ObjectProxy.h" +#include "server/HelloImp.h" +#include "server/WinServer.h" + +TEST_F(HelloTest, prxClose) +{ + auto comm = getCommunicator(); + + WinServer ws; + startServer(ws, WIN_CONFIG()); + + string obj = getObj(ws.getConfig(), "WinAdapter"); + + HelloPrx prx = comm->stringToProxy(obj); + prx->testClose(); + + EXPECT_EQ(HelloImp::_current.size(), 1); + + prx->tars_close(); + + TC_Common::msleep(10); + EXPECT_EQ(HelloImp::_current.size(), 0); + + stopServer(ws); + +} + +TEST_F(HelloTest, prxCloseInCoroutine) +{ + auto comm = getCommunicator(); + + WinServer ws; + startServer(ws, WIN_CONFIG()); + + string obj = getObj(ws.getConfig(), "WinAdapter"); + + HelloPrx prx = comm->stringToProxy(obj); + prx->testClose(); + + EXPECT_EQ(HelloImp::_current.size(), 1); + + funcInCoroutine([&](){ + prx->testClose(); + }); + + EXPECT_EQ(HelloImp::_current.size(), 2); + + prx->tars_close(); + + TC_Common::msleep(10); + EXPECT_EQ(HelloImp::_current.size(), 0); + + stopServer(ws); + +} \ No newline at end of file diff --git a/unit-test/rpc/test_proxy_timeout.cpp b/unit-test/rpc/test_proxy_timeout.cpp index 8b9e938b..89225b81 100755 --- a/unit-test/rpc/test_proxy_timeout.cpp +++ b/unit-test/rpc/test_proxy_timeout.cpp @@ -10,22 +10,28 @@ 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_push.cpp b/unit-test/rpc/test_push.cpp index 6b22be1f..62f7db0e 100755 --- a/unit-test/rpc/test_push.cpp +++ b/unit-test/rpc/test_push.cpp @@ -38,7 +38,12 @@ class RegisterPushCallBack : public PushPrxCallback _msg = msg; } - string _msg; + virtual void onClose(const TC_Endpoint& ep) { + _close = true; + }; + + string _msg; + bool _close = false; }; typedef TC_AutoPtr RegisterPushCallBackPtr; @@ -69,3 +74,35 @@ TEST_F(HelloTest, push) stopServer(ws); } + +TEST_F(HelloTest, pushClose) +{ + shared_ptr comm = getCommunicator(); + + WinServer ws; + startServer(ws, WIN_CONFIG()); + + string obj = getObj(ws.getConfig(), "WinAdapter"); + + HelloPrx prx = comm->stringToProxy(obj); + + RegisterPushCallBackPtr callback = new RegisterPushCallBack(); + + prx->tars_set_push_callback(callback); + + string msg = TC_Common::now2str(); + + prx->testPushRegister(msg); + + TC_Common::msleep(50); + + ASSERT_TRUE(callback->_msg == msg); + + prx->tars_close(); + + TC_Common::msleep(50); + + ASSERT_TRUE(callback->_close); + + stopServer(ws); +} diff --git a/unit-test/rpc/test_rpc.cpp b/unit-test/rpc/test_rpc.cpp index 202d0209..fb12683f 100755 --- a/unit-test/rpc/test_rpc.cpp +++ b/unit-test/rpc/test_rpc.cpp @@ -38,19 +38,19 @@ TEST_F(HelloTest, rpcSyncServerCommunicatorInCoroutine) }); } -TEST_F(HelloTest, rpcSyncAllocCommunicator) -{ - transAllocCommunicator([&](Communicator *comm){ - checkSync(comm); - }); -} - -TEST_F(HelloTest, rpcSyncAllocCommunicatorInCoroutine) -{ - transInCoroutineAllocCommunicator([&](Communicator *comm){ - checkSync(comm); - }); -} +//TEST_F(HelloTest, rpcSyncAllocCommunicator) +//{ +// transAllocCommunicator([&](Communicator *comm){ +// checkSync(comm); +// }); +//} +// +//TEST_F(HelloTest, rpcSyncAllocCommunicatorInCoroutine) +//{ +// transInCoroutineAllocCommunicator([&](Communicator *comm){ +// checkSync(comm); +// }); +//} TEST_F(HelloTest, rpcSyncComplexCommunicator) { @@ -97,11 +97,19 @@ TEST_F(HelloTest, rpcSyncComplexCommunicatorInCoroutine) TEST_F(HelloTest, rpcSyncIpV6GlobalCommunicator) { - shared_ptr c = getCommunicator(); - - transGlobalCommunicator([&](Communicator *comm){ - checkSync(comm, "Ipv6Adapter"); - }, c.get()); + HelloServer server; + startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) 0); + +// TC_Common::sleep(1000); + checkSync(server.getCommunicator().get(), "Ipv6Adapter"); + + stopServer(server); +// +// shared_ptr c = getCommunicator(); +// +// transGlobalCommunicator([&](Communicator *comm){ +// checkSync(comm, "Ipv6Adapter"); +// }, c.get()); } TEST_F(HelloTest, rpcSyncIpV6GlobalCommunicatorInCoroutine) diff --git a/unit-test/server/Hello.tars b/unit-test/server/Hello.tars index 4674eb6a..e96da05c 100755 --- a/unit-test/server/Hello.tars +++ b/unit-test/server/Hello.tars @@ -42,6 +42,11 @@ module Test 0 optional map json; }; + struct JsonDouble + { + 1 optional double d; + }; + interface Hello { int testTrans(int index, string s, out string r); @@ -63,6 +68,8 @@ module Test int testConHash(out string sOut); int testPushRegister(string msg); + + int testClose(); }; }; diff --git a/unit-test/server/HelloImp.cpp b/unit-test/server/HelloImp.cpp index 36b2900e..3f599d7b 100755 --- a/unit-test/server/HelloImp.cpp +++ b/unit-test/server/HelloImp.cpp @@ -95,9 +95,9 @@ int HelloImp::testHello(int index, const string& s, string& r, CurrentPtr curren // // if(index % 10000 == 0) // { - // LOG_CONSOLE_DEBUG << index << endl; // } ++hello_count; +// LOG_CONSOLE_DEBUG << hello_count << ", fd:" << current->getFd() << ", " << current->getIp() << ":" << current->getPort() << endl; r = s; return 0; @@ -159,4 +159,21 @@ int HelloImp::testPushRegister(const string &msg, CurrentPtr current) Push::async_response_push_testPush(current, 0, msg); return 0; } + +set HelloImp::_current; + +int HelloImp::testClose(CurrentPtr current) +{ +// LOG_CONSOLE_DEBUG << endl; + _current.insert(current->getUId()); + return 0; +} + +int HelloImp::doClose(CurrentPtr current) +{ +// LOG_CONSOLE_DEBUG << endl; + _current.erase(current->getUId()); + return 0; +} + /////////////////////////////////////////////////////////////////////////////// diff --git a/unit-test/server/HelloImp.h b/unit-test/server/HelloImp.h index 915b10af..00c99b4e 100755 --- a/unit-test/server/HelloImp.h +++ b/unit-test/server/HelloImp.h @@ -19,6 +19,8 @@ class HelloImp : public Hello { */ HelloImp(); + static set _current; + public: /** * 对象初始化 @@ -30,6 +32,13 @@ class HelloImp : public Hello { */ virtual void destroy(); + /** + * 关闭连接 + * @param current + * @return + */ + virtual int doClose(CurrentPtr current); + public: int testTrans(int index, const string &s, string &r, CurrentPtr current); @@ -51,6 +60,7 @@ class HelloImp : public Hello { virtual int testPushRegister(const string &msg, CurrentPtr current); + virtual int testClose(CurrentPtr current); protected: HelloPrx _helloPrx; diff --git a/unit-test/server/HelloServer.cpp b/unit-test/server/HelloServer.cpp index a421794d..0618904f 100755 --- a/unit-test/server/HelloServer.cpp +++ b/unit-test/server/HelloServer.cpp @@ -53,7 +53,8 @@ static TC_NetWorkBuffer::PACKET_TYPE parse(TC_NetWorkBuffer &in, vector &o void 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(); diff --git a/unit-test/server/client.conf b/unit-test/server/client.conf index 0f073867..df0fb2ce 100755 --- a/unit-test/server/client.conf +++ b/unit-test/server/client.conf @@ -4,8 +4,8 @@ #tarsregistry locator locator = TestApp.FrameworkServer.QueryObj@tcp -h 127.0.0.1 -p 11004 - #max invoke timeout sync-invoke-timeout = 50000 + async-invoke-timeout = 50000 #refresh endpoint interval refresh-endpoint-interval = 3000 #stat obj diff --git a/unit-test/util/test_server.h b/unit-test/util/test_server.h index 356e49a9..109f8049 100644 --- a/unit-test/util/test_server.h +++ b/unit-test/util/test_server.h @@ -120,6 +120,7 @@ class TcpQueueHandle : public TC_EpollServer::Handle shared_ptr send = data->createSendContext(); string buff(data->buffer().data(), data->buffer().size()); +// cout << "handle:" << buff << endl; buff += "-" + TC_Common::tostr(TC_Thread::CURRENT_THREADID()); @@ -234,7 +235,7 @@ class MyTcpServer void bindTcpQueue(const std::string &str) { - TC_EpollServer::BindAdapterPtr lsPtr = _epollServer->createBindAdapter("TcpQueueAdapter", str, 5); + TC_EpollServer::BindAdapterPtr lsPtr = _epollServer->createBindAdapter("TcpQueueAdapter", str, 5); lsPtr->enableQueueMode(); diff --git a/unit-test/util/test_tc_clientsocket.cpp b/unit-test/util/test_tc_clientsocket.cpp index 211ee3a9..53d9d6f9 100755 --- a/unit-test/util/test_tc_clientsocket.cpp +++ b/unit-test/util/test_tc_clientsocket.cpp @@ -30,7 +30,7 @@ class UtilClientSocketTest : public testing::Test TEST_F(UtilClientSocketTest, testParseEndpoint) { TC_Endpoint ep; - ep.parse("tcp -h 127.0.0.1 -p 17890 -t 3000:"); + ep.parse("tcp -h 127.0.0.1 -p 17890 -p 3000"); ASSERT_TRUE(ep.isTcp()); ASSERT_TRUE(ep.getHost() == "127.0.0.1"); diff --git a/unit-test/util/test_tc_docker.cpp b/unit-test/util/test_tc_docker.cpp index a7d9c43b..a997169f 100644 --- a/unit-test/util/test_tc_docker.cpp +++ b/unit-test/util/test_tc_docker.cpp @@ -160,7 +160,7 @@ TEST_F(DockerTest, inspectContainer) entrypoints.push_back("sleep"); entrypoints.push_back("100"); - bool succ = docker.create("test", "tarscloud/tars.nodejsbase:latest", entrypoints, {},{}, {}, {}, "", 0, "host", "none", true, false); + bool succ = docker.create("test", "busybox", entrypoints, {},{}, {}, {}, "", 0, "host", "none", true, false); LOG_CONSOLE_DEBUG << "inspectContainer:" << succ << ", " << (succ ? docker.getResponseMessage() : docker.getErrMessage()) << endl; ASSERT_TRUE(succ); diff --git a/unit-test/util/test_tc_endpoint.cpp b/unit-test/util/test_tc_endpoint.cpp new file mode 100644 index 00000000..37064218 --- /dev/null +++ b/unit-test/util/test_tc_endpoint.cpp @@ -0,0 +1,88 @@ +// +// Created by jarod on 2020/2/20. +// + +#include "util/tc_clientsocket.h" +#include "gtest/gtest.h" + +using namespace tars; + +class UtilEndpointTest : public testing::Test +{ +public: + //添加日志 + static void SetUpTestCase() + { +// cout<<"SetUpTestCase"< eps = TC_Endpoint::sepEndpoint(str); + + EXPECT_EQ(eps.size(), 1); + + EXPECT_EQ(eps[0], str); + + str = "tcp -h ::1 -p 25460 -t 60000"; + + eps = TC_Endpoint::sepEndpoint(str); + + EXPECT_EQ(eps.size(), 1); + + EXPECT_EQ(eps[0], str); + + str = "ssl -h ::1 -p 25460 -t 60000"; + + eps = TC_Endpoint::sepEndpoint(str); + + EXPECT_EQ(eps.size(), 1); + + EXPECT_EQ(eps[0], str); + + str = " tcp -h ::1 -p 25460 -t 60000 "; + + eps = TC_Endpoint::sepEndpoint(str); + + EXPECT_EQ(eps.size(), 1); + + EXPECT_EQ(eps[0], TC_Common::trim(str)); + + str = " tcp -h ::1 -p 25460 -t 60000: "; + + eps = TC_Endpoint::sepEndpoint(str); + + EXPECT_EQ(eps.size(), 1); + + EXPECT_EQ(eps[0], TC_Common::trim("tcp -h ::1 -p 25460 -t 60000")); +} + + +TEST_F(UtilEndpointTest, seps) +{ + string str = " udp -h ::1 -p 25460 -t 60000 : tcp -h 127.0.0.1 -p 25460 -t 60000 : ssl -h ::1 -p 25460 -t 60000: "; + + vector eps = TC_Endpoint::sepEndpoint(str); + + EXPECT_EQ(eps.size(), 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"); + EXPECT_EQ(eps[2], "ssl -h ::1 -p 25460 -t 60000"); + +} \ No newline at end of file diff --git a/unit-test/util/test_tc_epoller_server.cpp b/unit-test/util/test_tc_epoller_server.cpp index 44f33e4a..9a6bfa81 100644 --- a/unit-test/util/test_tc_epoller_server.cpp +++ b/unit-test/util/test_tc_epoller_server.cpp @@ -76,10 +76,11 @@ TEST_F(UtilEpollServerTest, RunUdp) for (int i = 0; i < 10; i++) { - iRet = client.sendRecv("abc", 3, recvBuffer, recvLenth); + string buff = "abc-" + TC_Common::tostr(i); + iRet = client.sendRecv(buff.c_str(), buff.size(), recvBuffer, recvLenth); ASSERT_TRUE(iRet == 0); - ASSERT_TRUE(string(recvBuffer, recvLenth) == "abc"); + ASSERT_TRUE(string(recvBuffer, recvLenth) == buff); } stopServer(server); @@ -126,15 +127,18 @@ TEST_F(UtilEpollServerTest, RunEnableManualListen) ASSERT_TRUE(iRet == -6); server.startManualListen(); + TC_Common::msleep(50); iRet = client.sendRecv("abc", 3, recvBuffer, recvLenth); ASSERT_TRUE(iRet == 0); ASSERT_TRUE(string(recvBuffer, recvLenth) == "abc"); server.cancelManualListen(); + TC_Common::msleep(50); iRet = client.sendRecv("abc", 3, recvBuffer, recvLenth); ASSERT_TRUE(iRet != TC_ClientSocket::EM_SUCCESS); server.startManualListen(); + TC_Common::msleep(50); iRet = client.sendRecv("abc", 3, recvBuffer, recvLenth); ASSERT_TRUE(iRet == 0); ASSERT_TRUE(string(recvBuffer, recvLenth) == "abc"); @@ -242,15 +246,18 @@ TEST_F(UtilEpollServerTest, ConnectionMax) TEST_F(UtilEpollServerTest, QueueMode) { for(int i = 0; i <= TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO; i++) +//int i = 2; { +// LOG_CONSOLE_DEBUG << "i:" << i << endl; MyTcpServer server; startServer(server, (TC_EpollServer::SERVER_OPEN_COROUTINE) i); vector conns; + int conn = 10; //注意服务连接数是10个 - for (int i = 0; i < 10; i++) { + for (int i = 0; i < conn; i++) { TC_TCPClient *client = new TC_TCPClient(QUEUE_HOST_EP.getHost(), QUEUE_HOST_EP.getPort(), QUEUE_HOST_EP.getTimeout()); @@ -265,7 +272,9 @@ TEST_F(UtilEpollServerTest, QueueMode) char recvBuffer[1024] = {0}; size_t recvLenth = 1024; - iRet = client->sendRecv("abc", 3, recvBuffer, recvLenth); +// LOG_CONSOLE_DEBUG << "send:" << i << endl; + + iRet = client->sendRecv("abc", 3, recvBuffer, recvLenth); ASSERT_TRUE(iRet == 0); diff --git a/unit-test/util/test_tc_http.cpp b/unit-test/util/test_tc_http.cpp index 90f8143c..db8ce74f 100644 --- a/unit-test/util/test_tc_http.cpp +++ b/unit-test/util/test_tc_http.cpp @@ -890,6 +890,7 @@ TEST_F(UtilHttpTest, testIncrementDecode3) } +#if TARS_HTTPS TEST_F(UtilHttpTest, testBaidus) //此时使用的是TEST_F宏 { string url = "https://www.baidu.com"; @@ -910,3 +911,4 @@ TEST_F(UtilHttpTest, testBaidus) //此时使用的是TEST_F宏 ASSERT_TRUE(stHttpRsp.getContentLength() == stHttpRsp.getContent().length()); } +#endif \ No newline at end of file diff --git a/unit-test/util/test_tc_json.cpp b/unit-test/util/test_tc_json.cpp index 4d512d4e..eadcf2ef 100644 --- a/unit-test/util/test_tc_json.cpp +++ b/unit-test/util/test_tc_json.cpp @@ -156,3 +156,16 @@ TEST_F(JsonTest, find) ASSERT_TRUE(aPtr->find(new JsonValueBoolean(false)) != aPtr->value.end()); // ASSERT_TRUE(aPtr->find(new JsonValueBoolean(true)) != aPtr->value.end()); } + +TEST_F(JsonTest, jsonDouble) +{ + JsonDouble jValue; + jValue.d = 1.32e1; + string v = jValue.writeToJsonString(); + + cout << "json1:" << v << endl; + v = "{\"d\":1.32e1}"; + + jValue.readFromJsonString(v); + cout << jValue.d << endl; +} \ No newline at end of file diff --git a/unit-test/util/test_tc_timeout_queue_map.cpp b/unit-test/util/test_tc_timeout_queue_map.cpp new file mode 100755 index 00000000..e79bc6d3 --- /dev/null +++ b/unit-test/util/test_tc_timeout_queue_map.cpp @@ -0,0 +1,57 @@ +#include "util/tc_timeout_queue_map.h" +#include "util/tc_common.h" +#include "gtest/gtest.h" + +#include +#include + +using namespace std; +using namespace tars; + +class UtilTimeoutQueueMapTest : public testing::Test +{ +public: + //添加日志 + static void SetUpTestCase() + { + } + static void TearDownTestCase() + { + } + virtual void SetUp() //TEST跑之前会执行SetUp + { + } + virtual void TearDown() //TEST跑完之后会执行TearDown + { + } +}; + +TEST_F(UtilTimeoutQueueMapTest, test) +{ + TC_TimeoutQueueMap queueMap; + queueMap.setTimeout(100); + + queueMap.push("abc1", "def1"); + queueMap.push("abc2", "def2"); + queueMap.push("abc", "def"); + + TC_Common::msleep(110); + queueMap.timeout(); + + EXPECT_EQ(queueMap.size(), 0); + ASSERT_FALSE(queueMap.has("abc")); + + queueMap.push("abc", "def1"); + TC_Common::msleep(50); + queueMap.push("abc", "def2"); + TC_Common::msleep(50); + queueMap.push("abc", "def3"); + TC_Common::msleep(50); + + queueMap.timeout(); + ASSERT_TRUE(queueMap.has("abc")); + EXPECT_EQ(queueMap.get("abc"), "def3"); + EXPECT_EQ(queueMap.size(), 1); + +} + diff --git a/util/include/util/tc_autoptr.h b/util/include/util/tc_autoptr.h index 4dd70c4b..e6430c72 100755 --- a/util/include/util/tc_autoptr.h +++ b/util/include/util/tc_autoptr.h @@ -339,6 +339,34 @@ class TC_AutoPtr return TC_AutoPtr(dynamic_cast(p)); } + /** + * @brief Replace other types of smart pointers with current types of smart pointers + * @brief 将其他类型的智能指针换成当前类型的智能指针. + * + * @param Y + * @param r + * @return TC_AutoPtr + */ + template + static TC_AutoPtr staticCast(const TC_AutoPtr& r) + { + return TC_AutoPtr(static_cast(r._ptr)); + } + + /** + * @brief Convert pointers of other native types into smart pointers of the current type + * @brief 将其他原生类型的指针转换成当前类型的智能指针. + * + * @param Y + * @param p + * @return TC_AutoPtr + */ + template + static TC_AutoPtr staticCast(Y* p) + { + return TC_AutoPtr(static_cast(p)); + } + /** * @brief Get Native Pointer * @brief 获取原生指针. diff --git a/util/include/util/tc_epoll_server.h b/util/include/util/tc_epoll_server.h index 131ed4bc..57feaf35 100755 --- a/util/include/util/tc_epoll_server.h +++ b/util/include/util/tc_epoll_server.h @@ -327,7 +327,7 @@ class TC_EpollServer : public TC_HandleBase, public detail::LogInterface * 构造, 传入handle处理线程, * @param handleNum */ - DataBuffer(int handleNum); + DataBuffer(int handleNum, TC_EpollServer *epollServer); /** * 通知唤醒 @@ -374,7 +374,7 @@ class TC_EpollServer : public TC_HandleBase, public detail::LogInterface * @param data * @return */ - size_t size(uint32_t handleIndex){ return getDataQueue(handleIndex)->size(); } + size_t size(size_t handleIndex){ return getDataQueue(handleIndex)->size(); } /** * 接收buffer的大小 @@ -410,12 +410,16 @@ class TC_EpollServer : public TC_HandleBase, public detail::LogInterface protected: - inline int index(uint32_t handleIndex) { return handleIndex % _threadDataQueue.size(); } + inline size_t index(size_t handleIndex) { return handleIndex % _threadDataQueue.size(); } - const shared_ptr &getDataQueue(uint32_t handleIndex); + const shared_ptr &getDataQueue(size_t handleIndex); protected: + /** + * epoll server + */ + TC_EpollServer *_epollServer; /** * 接收队列数据总个数 */ @@ -441,7 +445,7 @@ class TC_EpollServer : public TC_HandleBase, public detail::LogInterface /** * wait time for queue */ - int64_t _iWaitTime = 3000; + int64_t _iWaitTime = 1000; }; //////////////////////////////////////////////////////////////////////////// @@ -1432,7 +1436,7 @@ class TC_EpollServer : public TC_HandleBase, public detail::LogInterface _iHandleNum = n; - _dataBuffer.reset(new DataBuffer(_iHandleNum)); + _dataBuffer.reset(new DataBuffer(_iHandleNum, this->_epollServer)); for (size_t i = 0; i < _iHandleNum; ++i) { @@ -1811,7 +1815,7 @@ class TC_EpollServer : public TC_HandleBase, public detail::LogInterface /** * net线程的id */ - size_t _threadId; + uint64_t _threadId; /** * 线程索引 diff --git a/util/include/util/tc_logger.h b/util/include/util/tc_logger.h index 6c8c4877..daa8dbe7 100644 --- a/util/include/util/tc_logger.h +++ b/util/include/util/tc_logger.h @@ -264,7 +264,7 @@ namespace tars * Stained thread ID collection * */ - static unordered_map _mapThreadID; + static unordered_map _mapThreadID; }; typedef TC_AutoPtr TC_LoggerRollPtr; @@ -922,9 +922,9 @@ namespace tars TC_Port::localtime_r(&t, &tt); - const char *szFormat = (_bHasSquareBracket) ? ("[%04d-%02d-%02d %02d:%02d:%02d.%03ld]%s") : ("%04d-%02d-%02d %02d:%02d:%02d.%03ld%s"); + const char *szFormat = (_bHasSquareBracket) ? ("[%04d-%02d-%02d %02d:%02d:%02d.%03d]%s") : ("%04d-%02d-%02d %02d:%02d:%02d.%03d%s"); n += snprintf(c + n, len - n, szFormat, - tt.tm_year + 1900, tt.tm_mon + 1, tt.tm_mday, tt.tm_hour, tt.tm_min, tt.tm_sec, duration_in_ms % 1000, _sSepar.c_str()); + tt.tm_year + 1900, tt.tm_mon + 1, tt.tm_mday, tt.tm_hour, tt.tm_min, tt.tm_sec, (int)(duration_in_ms % 1000), _sSepar.c_str()); } else if (hasFlag(TC_Logger::HAS_TIME)) { @@ -944,7 +944,16 @@ namespace tars if (hasFlag(TC_Logger::HAS_PID)) { - n += snprintf(c + n, len - n, "%zd%s", TC_Thread::CURRENT_THREADID(), _sSepar.c_str()); +#if __WORDSIZE == 64 + +#if TARGET_PLATFORM_IOS + n += snprintf(c + n, len - n, "%llu%s", TC_Thread::CURRENT_THREADID(), _sSepar.c_str()); +#else + n += snprintf(c + n, len - n, "%lu%s", TC_Thread::CURRENT_THREADID(), _sSepar.c_str()); +#endif +#else + n += snprintf(c + n, len - n, "%llu%s", TC_Thread::CURRENT_THREADID(), _sSepar.c_str()); +#endif } if (hasFlag(TC_Logger::HAS_LEVEL)) diff --git a/util/include/util/tc_thread.h b/util/include/util/tc_thread.h index 05325628..42b9c091 100644 --- a/util/include/util/tc_thread.h +++ b/util/include/util/tc_thread.h @@ -206,7 +206,8 @@ class TC_Thread : public TC_Runable * * @return */ - static size_t CURRENT_THREADID(); + static uint64_t CURRENT_THREADID(); + protected: /** diff --git a/util/include/util/tc_timeout_queue_map.h b/util/include/util/tc_timeout_queue_map.h index dbef74ce..f48a94d2 100644 --- a/util/include/util/tc_timeout_queue_map.h +++ b/util/include/util/tc_timeout_queue_map.h @@ -1,568 +1,532 @@ -/** - * Tencent is pleased to support the open source community by making Tars available. - * - * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * https://opensource.org/licenses/BSD-3-Clause - * - * Unless required by applicable law or agreed to in writing, software distributed - * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - * CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - */ - -#ifndef __TC_TIMEOUT_QUEUE_MAP_H -#define __TC_TIMEOUT_QUEUE_MAP_H +#pragma once +#include #include +#include #include -#include "util/tc_timeprovider.h" - -using namespace std; +#include +#include +#include +#include namespace tars { -///////////////////////////////////////////////// /** - * @file tc_timeout_queue_map.h - * @brief 超时队列. - * + * 带队列模式的map, 并可以根据超时时间淘汰历史数据 + * - 向队列中Push的时候, 也会按照先后顺序排序 + * - 调用timeout, 会将超时的数据从内部删除 */ -///////////////////////////////////////////////// - -//超时时间精确单位是100ms -#define MAX_TIME_OUT 60000 - -template +template class TC_TimeoutQueueMap { public: - struct PtrInfo; - struct NodeInfo; - struct SendInfo; + struct PtrInfo; - struct NodeInfo - { - NodeInfo() - :id(0) - ,free(true) - ,noSendNext(0) - ,noSendPrev(0) - ,noSendPrevEnd(false) - ,timeoutNext(0) - ,timeoutPrev(0) - ,timeoutPrevEnd(false) - ,freeNext(0) - { - } - //request id - uint16_t id; - - //是否空闲 - bool free; - - bool hasSend; - - //未发送链表下一个id - uint16_t noSendNext; - //未发送链表前一个id - uint16_t noSendPrev; - //如果为false noSendPrev的值是requestid - //如果为true noSendPrev的值是 - bool noSendPrevEnd; - - //超时链表的下一个id - uint16_t timeoutNext; - //超时链表的前一个id - uint16_t timeoutPrev; - //如果为false timeoutPrev的值是requestid - //如果为true timeoutPrev的值是timeout数组的id - bool timeoutPrevEnd; - - //空闲链表的下一个id - uint16_t freeNext; - - T ptr; - }; + struct NodeInfo; - /** - * @brief 超时队列,缺省5s超时. - * - * @param timeout 超时设定时间 - * @param size - */ - TC_TimeoutQueueMap() - :_noSendHead(0) - ,_noSendTail(0) - ,_noSendSize(0) - ,_freeHead(1) - ,_timeoutPtr(0) - ,_timeoutPtrTime(0) - { - _dataSize = 51200; - _data = NULL; - _data = new NodeInfo[_dataSize]; - assert(NULL != _data); - - for(uint16_t i = 1; i < _dataSize; ++i) - { - _data[i].id = i; - _data[i].free = true; - _data[i].noSendNext = 0; - _data[i].noSendPrev = 0; - _data[i].timeoutNext = 0; - _data[i].timeoutPrev = 0; - _data[i].freeNext = i+1; - } - //最后free链表的next要改成0 - _data[_dataSize-1].freeNext = 0; - _freeHead = 1; - _freeTail = _dataSize-1; - - _timeoutSize = MAX_TIME_OUT >> 5; - _timeoutHead = NULL; - _timeoutHead = new uint16_t[_timeoutSize]; - - for(uint16_t i = 0; i < _timeoutSize; ++i) - { - _timeoutHead[i] = 0; - } - - _timeoutPtr = 0; - _timeoutPtrTime = 0; - } + typedef std::map data_type; - /** - * @brief 产生该队列的下一个ID - */ - uint32_t generateId(); + typedef std::list time_type; - /** - * 要发送的链表是否为空 - */ - bool sendListEmpty() - { - return (0 == _noSendHead); - } + typedef std::function data_functor; - /** - * 获取要发送的数据 - */ - bool getSend(T & t); + struct PtrInfo + { + T ptr; - /** - * 把已经发送的数据从list里面删除 - */ - void popSend(bool del = false); + typename time_type::iterator timeIter; + }; - /** - *获取要发送list的size - */ - size_t getSendListSize() - { - return _noSendSize; - } + struct NodeInfo + { + bool hasPoped; - /** - * @brief 获取指定id的数据. - * - * @param id 指定的数据的id - * @param T 指定id的数据 - * @return bool get的结果 - */ - bool get(uint16_t uniqId, T & t,bool bErase = true); + int64_t createTime; + + typename data_type::iterator dataIter; + }; + + /** + * @brief 超时队列,缺省5s超时. + * + * @param timeout 超时设定时间 + * @param size + */ + TC_TimeoutQueueMap(int timeout = 5 * 1000) + : _timeout(timeout) + { + _firstNoPopIter = _time.end(); + } + + /** + * @brief 设置超时时间(毫秒). + * + * @param timeout + */ + void setTimeout(time_t timeout) + { + _timeout = timeout; + } + + /** + * @brief 获取超时时间 + * @return [description] + */ + time_t getTimeout() const + { + return _timeout; + } + + /** + * 清空数据 + */ + void clear(); /** - * @brief 删除. + * @brief 是否存在key * - * @param uniqId 要删除的数据的id - * @param T 被删除的数据 - * @return bool 删除结果 + * @param k 指定的数据的key + * @return bool, true: 存在, false: 不存在 */ - bool erase(uint16_t uniqId, T & t); + bool has(const K & k); /** - * @brief 设置消息到队列尾端. + * @brief 是否存在key * - * @param ptr 要插入到队列尾端的消息 - * @param uniqId 序列号 - * @param timeout 超时时间 - * @return true 成功 false 失败 + * @param k 指定的数据的key + * @return T, 如果获取不到, 则抛出异常 */ - uint16_t push(T& ptr, uint16_t id, int64_t timeout,bool hasSend = true); + T get(const K & k); /** - * @brief 超时删除数据 - */ - bool timeout(T & t); + * @brief 获取指定key的数据. + * + * @param k 指定的数据的key + * @param t 获取指定key的数据 + * @return bool, true: 获取到数据, false: 没有获取到数据 + */ + bool get(const K & k, T & t, bool bErase = true); + + /** + * @brief, 获取数据并更新时间链, 从而能够不超时 + * @param k 指定的数据的key + * @param t 获取指定key的数据 + * @return bool, true: 获取到数据, false: 没有获取到数据 + */ + bool getAndRefresh(const K & k, T & t); + + /** + * @brief 删除. + * + * @param k 指定的数据的key + * @return bool, true: 数据存在, false: 数据不存在 + */ + bool erase(const K & k); + + /** + * @brief 删除. + * + * @param k 指定的数据的key + * @param t 如果数据存在, 则返回删除的数据 + * @return bool, true: 数据存在, false: 数据不存在 + */ + bool erase(const K & k, T & t); + + /** + * @brief 设置消息到队列尾端, 如果key存在, 则覆盖之前的 + * + * @param k 数据的key + * @param ptr 要插入到队列尾端的消息 + */ + void push(const K & k, const T & ptr); + + /** + * @brief 超时删除数据 + */ + void timeout(); + + /** + * @brief 删除超时的数据,并用df对数据做处理 + */ + void timeout(const data_functor & df); + + /** + * @brief 取出队列头部的消息 + * + * @param t + * @return true: 存在数据, false: 没有数据 + */ + bool pop(T & t); /** - * @brief 队列中的数据. - * - * @return size_t + * 获取队列头部数据, 如果没有则抛出异常 + * @return */ - size_t size() const { return _dataSize; } -private: - void delFromTimeout(uint16_t id); - void delFromData(uint16_t id); - void delFromNoSend(uint16_t id); + std::pair front(); + + /** + * @brief 队列中的数据. + * + * @return size_t + */ + size_t size() const + { + std::lock_guard lock(_mutex); + return _data.size(); + } + + /** + * @brief is empty + * @return + */ + bool empty() const + { + std::lock_guard lock(_mutex); + return _data.empty(); + } protected: - uint32_t _uniqId; - - uint16_t _dataSize; - - //未发送列表的head - uint16_t _noSendHead; - uint16_t _noSendTail; - - uint16_t _noSendSize; + int64_t _timeout; + data_type _data; + time_type _time; + typename time_type::iterator _firstNoPopIter; + mutable std::mutex _mutex; +}; - uint16_t * _timeoutHead; - uint16_t _timeoutSize; +template +void TC_TimeoutQueueMap::clear() +{ + std::lock_guard lock(_mutex); + _data.clear(); + _time.clear(); + _firstNoPopIter = _time.end(); +} - uint16_t _freeHead; - uint16_t _freeTail; - uint16_t _timeoutPtr; - int64_t _timeoutPtrTime; +template +bool TC_TimeoutQueueMap::has(const K & k) +{ + std::lock_guard lock(_mutex); + typename data_type::iterator it = _data.find(k); - NodeInfo * _data; -}; + return it != _data.end(); +} -template bool TC_TimeoutQueueMap::getSend(T & t) +template +T TC_TimeoutQueueMap::get(const K & k) { - //链表为空返回失败 - if(0 == _noSendHead) + std::lock_guard lock(_mutex); + typename data_type::iterator it = _data.find(k); + + if(it != _data.end()) { - return false; + return it->second.ptr; } - assert(!_data[_noSendHead].hasSend); - assert(!_data[_noSendHead].free); - t = _data[_noSendHead].ptr; - return true; + std::runtime_error("no data"); + return it->second.ptr; } - -template void TC_TimeoutQueueMap::popSend(bool del) +template +bool TC_TimeoutQueueMap::get(const K & k, T & t, bool bErase) { - assert(0 != _noSendHead); - assert(!_data[_noSendHead].hasSend); - assert(!_data[_noSendHead].free); + std::lock_guard lock(_mutex); - uint16_t popId = _noSendHead; + typename data_type::iterator it = _data.find(k); - //置成已经发送 - _data[popId].hasSend = true; + if (it == _data.end()) + { + return false; + } - //从nosend 里面删除 - delFromNoSend(popId); + t = it->second.ptr; - if(del) - { - delFromTimeout(popId); - delFromData(popId); - } + if (bErase) + { + if (_firstNoPopIter == it->second.timeIter) + { + ++_firstNoPopIter; + } + _time.erase(it->second.timeIter); + _data.erase(it); + } + + return true; } -template bool TC_TimeoutQueueMap::get(uint16_t id, T & t, bool bErase) +template +bool TC_TimeoutQueueMap::getAndRefresh(const K & k, T & t) { - assert(id < _dataSize); - if(id >= _dataSize) - { - return false; - } + std::lock_guard lock(_mutex); - if(_data[id].free) - { - return false; - } + typename data_type::iterator it = _data.find(k); - t = _data[id].ptr; + if (it == _data.end()) + { + return false; + } - if(bErase) - { - delFromTimeout(id); - delFromData(id); - } + t = it->second.ptr; - return true; -} + //从时间队列中删除 + if (_firstNoPopIter == it->second.timeIter) + { + ++_firstNoPopIter; + } + _time.erase(it->second.timeIter); -template uint32_t TC_TimeoutQueueMap::generateId() -{ - if(0 == _freeHead) - { - return 0; - } - assert(0 != _freeTail); + //再插入到时间队列末尾 + NodeInfo ni; - //从free里面找一个 - uint16_t id = _freeHead; - NodeInfo & node = _data[_freeHead]; - assert(node.free); - node.free = false; + ni.createTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - //修改free链表 - _freeHead = node.freeNext; - if(0 == _freeHead) - { - _freeTail = 0; - } - - return id; + ni.dataIter = it; + + ni.hasPoped = false; + + _time.push_back(ni); + + typename time_type::iterator tmp = _time.end(); + + --tmp; + + it->second.timeIter = tmp; + + if (_firstNoPopIter == _time.end()) + { + _firstNoPopIter = tmp; + } + + return true; } -template uint16_t TC_TimeoutQueueMap::push(T& ptr, uint16_t id, int64_t timeout, bool hasSend) +template +void TC_TimeoutQueueMap::push(const K & k, const T & ptr) { - //cerr<<"push:"<= _dataSize) - { - return false; - } + std::lock_guard lock(_mutex); - if(_data[id].free) - { - return false; - } + typename data_type::iterator it = _data.find(k); - //时间链表 初始化 - int64_t timeoutSelf = ( timeout >> 6); - if(0 == _timeoutPtrTime) - { - assert(0 == _timeoutPtr); - _timeoutPtrTime = (TNOWMS >> 6); - } + //如果重复插入的数据, 先从时间队列中删除 + if (it != _data.end()) + { + if (_firstNoPopIter == it->second.timeIter) + { + _firstNoPopIter++; + } + _time.erase(it->second.timeIter); + it->second.ptr = ptr; + } + else + { + PtrInfo pi; + pi.ptr = ptr; - if(timeoutSelf <= _timeoutPtrTime) - { - assert(false); - return 0; - } + //写入新数据, 返回新的迭代器内容 + std::pair result; - //检查超时时间是否合法 - if((timeoutSelf - _timeoutPtrTime) >= (int64_t)_timeoutSize) - { - assert(false); - return 0; - } + result = _data.insert(make_pair(k, pi)); - //从free里面找一个 -#if 0 - uint16_t id = _freeHead; - NodeInfo & node = _data[_freeHead]; - assert(node.free); - node.ptr = ptr; - node.hasSend = hasSend; - node.free = false; - - //修改free链表 - _freeHead = node.freeNext; - if(0 == _freeHead) - { - _freeTail = 0; - } -#endif - NodeInfo & node = _data[id]; - node.ptr = ptr; - node.hasSend = hasSend; + it = result.first; + } - //加入到时间链表里面 - uint16_t timeoutPtr; - timeoutPtr = (uint16_t)(timeoutSelf - _timeoutPtrTime) + _timeoutPtr; - timeoutPtr = timeoutPtr % _timeoutSize; + //更新时间队列 + NodeInfo ni; - if(0 == _timeoutHead[timeoutPtr]) - { - node.timeoutNext = 0; - } - else - { - uint16_t nextId = _timeoutHead[timeoutPtr]; - assert(_data[nextId].timeoutPrevEnd); - _data[nextId].timeoutPrev = id; - _data[nextId].timeoutPrevEnd = false; + ni.createTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - _data[id].timeoutNext = nextId; - } - node.timeoutPrevEnd = true; - node.timeoutPrev = timeoutPtr; - _timeoutHead[timeoutPtr] = id; - - //没有发送放到list队列里面 - if(!hasSend) - { - _noSendSize ++; - if(0 == _noSendTail) - { - assert(0 == _noSendHead); - _noSendHead = id; - _data[id].noSendPrev = 0; - } - else - { - assert(0 != _noSendHead); - _data[_noSendTail].noSendNext = id; - _data[id].noSendPrev = _noSendTail; - } - _data[id].noSendNext = 0; - _noSendTail = id; - } + ni.dataIter = it; + + ni.hasPoped = false; + + _time.push_back(ni); + + typename time_type::iterator tmp = _time.end(); + + --tmp; - return id; + it->second.timeIter = tmp; + + if (_firstNoPopIter == _time.end()) + { + _firstNoPopIter = tmp; + } } -template bool TC_TimeoutQueueMap::timeout(T & t) +template +void TC_TimeoutQueueMap::timeout() { - if(0 == _timeoutPtrTime) - { - return false; - } + auto ms = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + + while (true) + { + std::lock_guard lock(_mutex); + + typename time_type::iterator it = _time.begin(); + + if (it != _time.end() && ms - it->createTime > _timeout) + { + _data.erase(it->dataIter); + + if (_firstNoPopIter == it) + { + ++_firstNoPopIter; + } + _time.erase(it); + } + else + { + break; + } + } +} - int64_t nowSelf = TNOWMS >> 6; +template +void TC_TimeoutQueueMap::timeout(const data_functor & df) +{ + auto ms = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); - while(true) - { - if(_timeoutPtrTime >= nowSelf) - { - return false; - } - if(0 == _timeoutHead[_timeoutPtr]) - { - _timeoutPtr++; - _timeoutPtrTime ++; - if(_timeoutSize == _timeoutPtr) - { - _timeoutPtr = 0; - } - } - else - { - uint16_t id = _timeoutHead[_timeoutPtr]; - NodeInfo & node = _data[id]; - t = node.ptr; - if(!node.hasSend) - { - delFromNoSend(id); - } - delFromTimeout(id); - delFromData(id); - return true; - } - } - return true; + while (true) + { + { + _mutex.lock(); + + typename time_type::iterator it = _time.begin(); + + if (it != _time.end() && ms - it->createTime > _timeout) + { + auto v = *it->dataIter; + + _data.erase(it->dataIter); + + if (_firstNoPopIter == it) + { + _firstNoPopIter++; + } + _time.erase(it); + + _mutex.unlock(); + + try { df(v.first, v.second.ptr); } catch (...) {} + } + else + { + _mutex.unlock(); + break; + } + } + + } } -template bool TC_TimeoutQueueMap::erase(uint16_t id, T & t) +template +bool TC_TimeoutQueueMap::erase(const K & k) { - //cerr<<"line:"<<__LINE__<<" erase:"<= _dataSize) - { - return false; - } + std::lock_guard lock(_mutex); - if(_data[id].free) - { - return false; - } + typename data_type::iterator it = _data.find(k); - t = _data[id].ptr; - if(!_data[id].hasSend) - { - delFromNoSend(id); - } - delFromTimeout(id); - delFromData(id); + if (it == _data.end()) + { + return false; + } + + if (_firstNoPopIter == it->second.timeIter) + { + _firstNoPopIter++; + } + _time.erase(it->second.timeIter); - return true; + _data.erase(it); + + return true; } -template void TC_TimeoutQueueMap::delFromTimeout(uint16_t delId) +template +bool TC_TimeoutQueueMap::erase(const K & k, T & t) { - //从超时里面删除 - if(_data[delId].timeoutPrevEnd) - { - //cerr<<"line:"<<__LINE__< lock(_mutex); + + typename data_type::iterator it = _data.find(k); + + if (it == _data.end()) + { + return false; + } + + t = it->second.ptr; + + if (_firstNoPopIter == it->second.timeIter) + { + _firstNoPopIter++; + } + _time.erase(it->second.timeIter); + + _data.erase(it); + + return true; } -template void TC_TimeoutQueueMap::delFromData(uint16_t id) +template +bool TC_TimeoutQueueMap::pop(T & ptr) { - //放了链表最后 - _data[id].freeNext = 0; - if(0 == _freeTail) - { - assert(0 == _freeHead); - _freeHead = id; - } - else - { - assert(0 != _freeHead); - _data[_freeTail].freeNext = id; - } - _freeTail = id; - _data[id].free = true; + std::lock_guard lock(_mutex); + + if (_time.empty()) + { + return false; + } + + typename time_type::iterator it = _time.begin(); + + if (it->hasPoped == true) + { + it = _firstNoPopIter; + } + + if (it == _time.end()) + { + return false; + } + + assert(it->hasPoped == false); + + ptr = it->dataIter->second.ptr; + + it->hasPoped = true; + + _firstNoPopIter = it; + + ++_firstNoPopIter; + + return true; } -template void TC_TimeoutQueueMap::delFromNoSend(uint16_t id) +template +std::pair TC_TimeoutQueueMap::front() { - uint16_t prevId,nextId; - prevId = _data[id].noSendPrev; - nextId = _data[id].noSendNext; - - assert(_noSendSize>0); - _noSendSize --; + std::lock_guard lock(_mutex); - if(0 == prevId) - { - _noSendHead = nextId; - } - else + if (_time.empty()) { - _data[prevId].noSendNext = nextId; + throw std::runtime_error("no data exists"); } - if(0 == nextId) + typename time_type::iterator it = _time.begin(); + + if (it->hasPoped == true) { - _noSendTail = 0; + it = _firstNoPopIter; } - else + + if (it == _time.end()) { - _data[nextId].noSendPrev = prevId; + throw std::runtime_error("no data exists"); } + + assert(it->hasPoped == false); + + return std::make_pair(it->dataIter->first, it->dataIter->second.ptr); } -///////////////////////////////////////////////////////////////// } -#endif diff --git a/util/include/util/tc_transceiver.h b/util/include/util/tc_transceiver.h index b9f4c729..a3674024 100644 --- a/util/include/util/tc_transceiver.h +++ b/util/include/util/tc_transceiver.h @@ -168,7 +168,7 @@ class TC_Transceiver /** * 构造函数 * @param epoller - * @param ep, 服务端地址 + * @param ep, 如果是服务器端的连接, 则为服务端地址, 如果为客户端发起的连接, 也为服务器地址 */ TC_Transceiver(TC_Epoller* epoller, const TC_Endpoint &ep); @@ -477,7 +477,7 @@ class TC_Transceiver /** * 解析域名 */ - void parseConnectAddress(); + void parseConnectAddress(const TC_Endpoint &ep); /** * 发送鉴权代码 diff --git a/util/src/tc_clientsocket.cpp b/util/src/tc_clientsocket.cpp index c338f484..caa49a22 100644 --- a/util/src/tc_clientsocket.cpp +++ b/util/src/tc_clientsocket.cpp @@ -258,47 +258,64 @@ void TC_Endpoint::parse(const string &str) vector TC_Endpoint::sepEndpoint(const string& sEndpoints) { - vector vEndpoints; - bool flag = false; - string::size_type startPos = 0; - string::size_type sepPos = string::npos; - for(string::size_type pos = 0; pos < sEndpoints.size(); pos++) - { - if(sEndpoints[pos] == ':' && !flag ) - { - sepPos = pos; - flag = true; - } - else if(flag) - { - if(sEndpoints[pos] == ' ') - { - continue; - } + std::vector result; + + std::function findSep = [](const std::string &str, size_t startPos) -> size_t { + // 查找下一个协议出现的位置 + size_t udpPos = str.find("udp", startPos); + size_t tcpPos = str.find("tcp", startPos); + size_t sslPos = str.find("ssl", startPos); + + // 找到最小的非空位置 + size_t foundPos = std::string::npos; + if (udpPos != std::string::npos) { + foundPos = udpPos; + } + if (tcpPos != std::string::npos) { + if (foundPos == std::string::npos || tcpPos < foundPos) { + foundPos = tcpPos; + } + } + if (sslPos != std::string::npos) { + if (foundPos == std::string::npos || sslPos < foundPos) { + foundPos = sslPos; + } + } - if(TC_Port::strncasecmp("tcp", (sEndpoints.c_str() + pos), 3) == 0 - || TC_Port::strncasecmp("udp", (sEndpoints.c_str() + pos), 3) == 0 - || TC_Port::strncasecmp("ssl", (sEndpoints.c_str() + pos), 3) == 0) - { - string ep = TC_Common::trim(string(sEndpoints.c_str() + startPos, sepPos - startPos)); - if(!ep.empty()) - { - vEndpoints.push_back(ep); - } - startPos = pos; - } + return foundPos; + }; - flag = false; - } - } + size_t startPos = 0; + size_t foundPos = findSep(sEndpoints, startPos); - string ep = sEndpoints.substr(startPos, sepPos-startPos); + while (foundPos != std::string::npos) { - if(!ep.empty()) { - vEndpoints.push_back(ep); - } + size_t lastFoundPos = foundPos; + startPos = foundPos + 3; // 增加3以跳过协议名称的长度 + foundPos = findSep(sEndpoints, startPos); + + //把上一个找到的字符串分隔并记录 + if(foundPos != std::string::npos) + { + string ep = TC_Common::trim(sEndpoints.substr(lastFoundPos, foundPos - lastFoundPos), " :"); + if(!ep.empty()) + { + result.push_back(ep); + } + } + else + { + //找不到下个了, 记录上一个并结束循环 + string ep = TC_Common::trim(sEndpoints.substr(lastFoundPos), " :"); + if(!ep.empty()) + { + result.push_back(ep); + } + break; + } + } - return vEndpoints; + return result; } diff --git a/util/src/tc_coroutine.cpp b/util/src/tc_coroutine.cpp index 90b67538..3da86e16 100755 --- a/util/src/tc_coroutine.cpp +++ b/util/src/tc_coroutine.cpp @@ -326,8 +326,6 @@ TC_CoroutineScheduler::TC_CoroutineScheduler() , _currentCoro(NULL) , _all_coro(NULL) { - // LOG_CONSOLE_DEBUG << endl; - _epoller = new TC_Epoller(); _epoller->create(10240); @@ -335,7 +333,6 @@ TC_CoroutineScheduler::TC_CoroutineScheduler() TC_CoroutineScheduler::~TC_CoroutineScheduler() { - // LOG_CONSOLE_DEBUG << endl; if(_epoller) { delete _epoller; @@ -666,6 +663,12 @@ void TC_CoroutineScheduler::terminate() assert(_epoller); _epoller->terminate(); +// +// if(_epoller) +// { +// delete _epoller; +// _epoller = NULL; +// } } uint32_t TC_CoroutineScheduler::generateId() @@ -816,6 +819,8 @@ void TC_Coroutine::run() handleCoro(); destroy(); + +// TC_CoroutineScheduler::reset(); } void TC_Coroutine::terminate() diff --git a/util/src/tc_epoll_server.cpp b/util/src/tc_epoll_server.cpp index ccd5bf90..75ac44c4 100644 --- a/util/src/tc_epoll_server.cpp +++ b/util/src/tc_epoll_server.cpp @@ -34,135 +34,168 @@ namespace tars void TC_EpollServer::RecvContext::parseIpPort() const { - if (_ip.empty()) - { - TC_Socket::parseAddr(_addr, _ip, _port); - } + if (_ip.empty()) + { + TC_Socket::parseAddr(_addr, _ip, _port); + } } -TC_EpollServer::DataBuffer::DataBuffer(int handleNum) +TC_EpollServer::DataBuffer::DataBuffer(int handleNum, TC_EpollServer *epollServer) { - for(int i = 0; i < handleNum; i++) - { - _threadDataQueue.push_back(std::make_shared()); - } + _epollServer = epollServer; + + for(int i = 0; i < handleNum; i++) + { + _threadDataQueue.push_back(std::make_shared()); + } - _schedulers.resize(handleNum); - for(size_t i = 0; i < _schedulers.size(); i++) - { - _schedulers[i] = NULL; - } + _schedulers.resize(handleNum); + for(size_t i = 0; i < _schedulers.size(); i++) + { + _schedulers[i] = NULL; + } } -const shared_ptr &TC_EpollServer::DataBuffer::getDataQueue(uint32_t handleIndex) +const shared_ptr &TC_EpollServer::DataBuffer::getDataQueue(size_t handleIndex) { - //如果是队列模式, 则返回handle线程对应的队列 - if(isQueueMode()) - { - return _threadDataQueue[index(handleIndex)]; - } + //如果是队列模式, 则返回handle线程对应的队列 + if(isQueueMode()) + { +// LOG_CONSOLE_DEBUG << "handleIndex:" << handleIndex << ", data queue index:" << index(handleIndex) << endl; + return _threadDataQueue[index(handleIndex)]; + } - //否则返回第一个队列(所有人共享) - return _threadDataQueue[0]; + //否则返回第一个队列(所有人共享) + return _threadDataQueue[0]; } void TC_EpollServer::DataBuffer::notifyBuffer(uint32_t handleIndex) { - getDataQueue(handleIndex)->notify(); + getDataQueue(handleIndex)->notify(); } void TC_EpollServer::DataBuffer::insertRecvQueue(const shared_ptr &recv) { - ++_iRecvBufferSize; +// LOG_CONSOLE_DEBUG << endl; + ++_iRecvBufferSize; - getDataQueue(recv->uid())->push_back(recv); + if(_epollServer->getOpenCoroutine() == TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD || _epollServer->getOpenCoroutine() == TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO) + { + //协程模式本身也是队列模式 + getDataQueue(recv->threadIndex())->push_back(recv); + } + else + { + //非协程模式下, getDataQueue会判断是否是队列模式 + getDataQueue(recv->uid())->push_back(recv); + } - if(_schedulers[0] != NULL) - { - //存在调度器, 处于协程中 - if(isQueueMode()) - { - _schedulers[index(recv->uid())]->notify(); - } - else - { - _schedulers[index(rand())]->notify(); - } - } + if(_schedulers[0] != NULL) + { + if(_epollServer->getOpenCoroutine() == TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD || _epollServer->getOpenCoroutine() == TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO) + { + _schedulers[index(recv->threadIndex())]->notify(); + } + else + { + //存在调度器, 处于协程中 + if (isQueueMode()) + { + _schedulers[index(recv->uid())]->notify(); + } + else + { + _schedulers[index(rand())]->notify(); + } + } + } } void TC_EpollServer::DataBuffer::insertRecvQueue(const deque> &recv) { - if (recv.empty()) - { - return; - } + if (recv.empty()) + { + return; + } - _iRecvBufferSize += recv.size(); + _iRecvBufferSize += recv.size(); - getDataQueue(recv.back()->uid())->push_back(recv); + if(_epollServer->getOpenCoroutine() == TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD || _epollServer->getOpenCoroutine() == TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO) + { + //协程模式本身也是队列模式 + getDataQueue(recv.back()->threadIndex())->push_back(recv); + } + else + { + //非协程模式下, getDataQueue会判断是否是队列模式 + getDataQueue(recv.back()->uid())->push_back(recv); + } - if (_schedulers[0] != NULL) - { - //存在调度器, 处于协程中 - if (isQueueMode()) - { - _schedulers[index(recv.back()->uid())]->notify(); - } - else - { - _schedulers[index(rand())]->notify(); - } - } + if (_schedulers[0] != NULL) + { + if(_epollServer->getOpenCoroutine() == TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD || _epollServer->getOpenCoroutine() == TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO) + { + _schedulers[index(recv.back()->threadIndex())]->notify(); + } + else + { + //存在调度器, 处于协程中 + if (isQueueMode()) { + _schedulers[index(recv.back()->uid())]->notify(); + } else { + _schedulers[index(rand())]->notify(); + } + } + } } bool TC_EpollServer::DataBuffer::wait(uint32_t handleIndex) { - return getDataQueue(handleIndex)->wait(_iWaitTime); + return getDataQueue(handleIndex)->wait(_iWaitTime); } bool TC_EpollServer::DataBuffer::pop(uint32_t handleIndex, shared_ptr &data) { - bool bRet = getDataQueue(handleIndex)->pop_front(data); + bool bRet = getDataQueue(handleIndex)->pop_front(data); - if (!bRet) - { - return bRet; - } + if (!bRet) + { + return bRet; + } - --_iRecvBufferSize; + --_iRecvBufferSize; - return bRet; + return bRet; } void TC_EpollServer::DataBuffer::registerScheduler(uint32_t handleIndex, const shared_ptr &scheduler) { - assert(handleIndex < _schedulers.size()); + assert(handleIndex < _schedulers.size()); - // LOG_CONSOLE_DEBUG << handleIndex << ", " << _schedulers.size() << endl; + // LOG_CONSOLE_DEBUG << handleIndex << ", " << _schedulers.size() << endl; - _schedulers[handleIndex] = scheduler; + _schedulers[handleIndex] = scheduler; } void TC_EpollServer::DataBuffer::unregisterScheduler(uint32_t handleIndex) { - // LOG_CONSOLE_DEBUG << handleIndex << ", " << _schedulers.size() << endl; - assert(handleIndex < _schedulers.size()); + // LOG_CONSOLE_DEBUG << handleIndex << ", " << _schedulers.size() << endl; + assert(handleIndex < _schedulers.size()); - _schedulers[handleIndex] = NULL; + _schedulers[handleIndex] = NULL; } const shared_ptr &TC_EpollServer::DataBuffer::getScheduler(uint32_t handleIndex) { - assert(handleIndex < _schedulers.size()); + assert(handleIndex < _schedulers.size()); - return _schedulers[handleIndex]; + return _schedulers[handleIndex]; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // handle的实现 TC_EpollServer::Handle::Handle() - : _epollServer(NULL) + : _epollServer(NULL) { } @@ -172,7 +205,7 @@ TC_EpollServer::Handle::~Handle() void TC_EpollServer::Handle::setWaitTime(uint32_t iWaitTime) { - this->getBindAdapter()->getDataBuffer()->setWaitTime(iWaitTime); + this->getBindAdapter()->getDataBuffer()->setWaitTime(iWaitTime); } void TC_EpollServer::Handle::handleClose(const shared_ptr & data) @@ -181,212 +214,216 @@ void TC_EpollServer::Handle::handleClose(const shared_ptr & data) void TC_EpollServer::Handle::handleTimeout(const shared_ptr & data) { - _epollServer->error("[Handle::handleTimeout] queue timeout, close [" + data->ip() + ":" + TC_Common::tostr(data->port()) + "]."); + _epollServer->error("[Handle::handleTimeout] queue timeout, close [" + data->ip() + ":" + TC_Common::tostr(data->port()) + "]."); - close(data); + close(data); } void TC_EpollServer::Handle::handleOverload(const shared_ptr & data) { - auto adapter = data->adapter(); + auto adapter = data->adapter(); - if(adapter) - { - _epollServer->error("[Handle::handleOverload] adapter '" + adapter->getName() + "',over load:" - + TC_Common::tostr(adapter->getRecvBufferSize()) + ">" - + TC_Common::tostr(adapter->getQueueCapacity()) + "."); - } + if(adapter) + { + _epollServer->error("[Handle::handleOverload] adapter '" + adapter->getName() + "',over load:" + + TC_Common::tostr(adapter->getRecvBufferSize()) + ">" + + TC_Common::tostr(adapter->getQueueCapacity()) + "."); + } - close(data); + close(data); } void TC_EpollServer::Handle::terminate() { // _terminate = true; - notifyFilter(); + notifyFilter(); } void TC_EpollServer::Handle::handleOnceCoroutine() { - const shared_ptr &scheduler = TC_CoroutineScheduler::scheduler(); - - assert(scheduler); - - //上报心跳 - heartbeat(); - - //为了实现所有主逻辑的单线程化,在每次循环中给业务处理自有消息的机会 - handleAsyncResponse(); - handleCustomMessage(true); - - bool bYield = false; - - shared_ptr data; - try - { - int loop = 1000; - - while ((loop--) > 0 && !_epollServer->isTerminate()) - { - if ((scheduler->getFreeSize() > 0) && _dataBuffer->pop(_handleIndex, data)) - { - bYield = true; - - //上报心跳 - heartbeat(); - - //为了实现所有主逻辑的单线程化,在每次循环中给业务处理自有消息的机会 - handleAsyncResponse(); - - if (data->isOverload()) - { - //数据已超载 overload - handleOverload(data); - } - else if (data->isClosed()) - { - //关闭连接的通知消息 - handleClose(data); - } - else if ((TNOWMS - data->recvTimeStamp()) > (uint64_t)_bindAdapter->getQueueTimeout()) - { - //数据在队列中已经超时了 - handleTimeout(data); - } - else - { - uint32_t iRet = scheduler->go(std::bind(&Handle::handle, this, data)); - if (iRet == 0) - { + const shared_ptr &scheduler = TC_CoroutineScheduler::scheduler(); + + assert(scheduler); + + //上报心跳 + heartbeat(); + + //为了实现所有主逻辑的单线程化,在每次循环中给业务处理自有消息的机会 + handleAsyncResponse(); + handleCustomMessage(true); + + bool bYield = false; + + shared_ptr data; + try + { + int loop = 1000; + + while ((loop--) > 0 && !_epollServer->isTerminate()) + { + if ((scheduler->getFreeSize() > 0) && _dataBuffer->pop(_handleIndex, data)) + { + bYield = true; + + //上报心跳 + heartbeat(); + + //为了实现所有主逻辑的单线程化,在每次循环中给业务处理自有消息的机会 + handleAsyncResponse(); + + if (data->isOverload()) + { + //数据已超载 overload + handleOverload(data); + } + else if (data->isClosed()) + { + //关闭连接的通知消息 + handleClose(data); + } + else if ((TNOWMS - data->recvTimeStamp()) > (uint64_t)_bindAdapter->getQueueTimeout()) + { + //数据在队列中已经超时了 + handleTimeout(data); + } + else + { + uint32_t iRet = scheduler->go(std::bind(&Handle::handle, this, data)); + if (iRet == 0) + { // LOG_CONSOLE_DEBUG << "handleOverload" << endl; - handleOverload(data); - } - } - handleCustomMessage(false); - } - else - { - bYield = false; - break; - } - } - - //循环100次, 没有任何消息需要处理, yield一下 - if (loop == 0) { - bYield = false; - } - } - catch (exception& ex) - { - if (data) - { - close(data); - } - - getEpollServer()->error("[TC_EpollServer::Handle::handleOnceCoroutine] error:" + string(ex.what())); - } - catch (...) - { - if (data) - { - close(data); - } - - getEpollServer()->error("[TC_EpollServer::Handle::handleOnceCoroutine] unknown error"); - } - - if (!bYield) - { - scheduler->yield(); - } - else if(scheduler->isMainCoroutine()) - { - scheduler->notify(); - } + handleOverload(data); + } + } + handleCustomMessage(false); + } + else + { + bYield = false; + break; + } + } + + //循环100次, 没有任何消息需要处理, yield一下 + if (loop == 0) { + bYield = false; + } + } + catch (exception& ex) + { + if (data) + { + close(data); + } + + getEpollServer()->error("[TC_EpollServer::Handle::handleOnceCoroutine] error:" + string(ex.what())); + } + catch (...) + { + if (data) + { + close(data); + } + + getEpollServer()->error("[TC_EpollServer::Handle::handleOnceCoroutine] unknown error"); + } + + if (!bYield) + { + scheduler->yield(); + } + else if(scheduler->isMainCoroutine()) + { + scheduler->notify(); + } // LOG_CONSOLE("handleOnceCoroutine ok"); } void TC_EpollServer::Handle::handleCoroutine() { - for(;;) - { - handleOnceCoroutine(); - } + for(;;) + { + handleOnceCoroutine(); + } } void TC_EpollServer::Handle::handleOnceThread() { - //上报心跳 - heartbeat(); - - //为了实现所有主逻辑的单线程化,在每次循环中给业务处理自有消息的机会 - handleAsyncResponse(); - handleCustomMessage(true); - - shared_ptr data; - - int loop = 100; - - while ((loop--) > 0 && _dataBuffer->pop(_handleIndex, data)) - { - try - { - //上报心跳 - heartbeat(); - - //为了实现所有主逻辑的单线程化,在每次循环中给业务处理自有消息的机会 - handleAsyncResponse(); - - if (data->isOverload()) - { - //数据已超载 overload - handleOverload(data); - } else if (data->isClosed()) - { - //关闭连接的通知消息 - handleClose(data); - } else if ((TNOWMS - data->recvTimeStamp()) > (uint64_t) _bindAdapter->getQueueTimeout()) - { - //数据在队列中已经超时了 - handleTimeout(data); - } else - { - handle(data); - } - handleCustomMessage(false); - } - catch (exception &ex) - { - if (data) - { - close(data); - } - - getEpollServer()->error("[Handle::handleImp] error:" + string(ex.what())); - } - catch (...) - { - if (data) - { - close(data); - } - - getEpollServer()->error("[Handle::handleImp] unknown error"); - } - } - - - if (loop <= 0 && _dataBuffer->size(_handleIndex) > 0) - { - //NET_THREAD_MERGE_HANDLES_THREAD模式下,_dataBuffer中还有数据,需要通知再次处理 - //NET_THREAD_QUEUE_HANDLES_THREAD模式下不需要通知,handleLoopThread循环中会自动再次处理 - if (_epollServer->getOpenCoroutine() == NET_THREAD_MERGE_HANDLES_THREAD) - { - notifyFilter(); - } - } + //上报心跳 + heartbeat(); + + //为了实现所有主逻辑的单线程化,在每次循环中给业务处理自有消息的机会 + handleAsyncResponse(); + handleCustomMessage(true); + + shared_ptr data; + + int loop = 100; + + while ((loop--) > 0 && _dataBuffer->pop(_handleIndex, data)) + { +// LOG_CONSOLE_DEBUG << "handleIndex1:" << _handleIndex << endl; + try + { + //上报心跳 + heartbeat(); + + //为了实现所有主逻辑的单线程化,在每次循环中给业务处理自有消息的机会 + handleAsyncResponse(); + + if (data->isOverload()) + { + //数据已超载 overload + handleOverload(data); + } else if (data->isClosed()) + { + //关闭连接的通知消息 + handleClose(data); + } else if ((TNOWMS - data->recvTimeStamp()) > (uint64_t) _bindAdapter->getQueueTimeout()) + { + //数据在队列中已经超时了 + handleTimeout(data); + } else + { + handle(data); + } + handleCustomMessage(false); + } + catch (exception &ex) + { + if (data) + { + close(data); + } + + getEpollServer()->error("[Handle::handleImp] error:" + string(ex.what())); + } + catch (...) + { + if (data) + { + close(data); + } + + getEpollServer()->error("[Handle::handleImp] unknown error"); + } + } + +// LOG_CONSOLE_DEBUG << "handleIndex2:" << _handleIndex << ", size:" << _dataBuffer->size(_handleIndex) << endl; + + if (loop <= 0 && _dataBuffer->size(_handleIndex) > 0) + { + //NET_THREAD_MERGE_HANDLES_THREAD模式下,_dataBuffer中还有数据,需要通知再次处理 + //NET_THREAD_QUEUE_HANDLES_THREAD模式下不需要通知,handleLoopThread循环中会自动再次处理 + if (_epollServer->getOpenCoroutine() == NET_THREAD_MERGE_HANDLES_THREAD) + { +// LOG_CONSOLE_DEBUG << "notifyFilter:" << _handleIndex << endl; + + notifyFilter(); + } + } // if (loop <= 0) // { @@ -400,426 +437,431 @@ void TC_EpollServer::Handle::handleOnceThread() bool TC_EpollServer::Handle::isReady() const { - if(this->_epollServer->getOpenCoroutine() == NET_THREAD_QUEUE_HANDLES_THREAD) - { - return true; - } - else if(this->_epollServer->getOpenCoroutine() == NET_THREAD_QUEUE_HANDLES_CO) - { - return _scheduler && _scheduler->isReady(); - } + if(this->_epollServer->getOpenCoroutine() == NET_THREAD_QUEUE_HANDLES_THREAD) + { + return true; + } + else if(this->_epollServer->getOpenCoroutine() == NET_THREAD_QUEUE_HANDLES_CO) + { + return _scheduler && _scheduler->isReady(); + } - assert(false); + assert(false); - return false; + return false; } void TC_EpollServer::Handle::handleLoopCoroutine() { - //这种模式下, 为了保证当前线程能做和通信器结合, 必须也等在epoll上 - //因此当网络层收到数据, 写对队列后, 需要唤醒某一个handle的epoll, 从而唤醒某个协程 - _scheduler = TC_CoroutineScheduler::create(); - _scheduler->setPoolStackSize(this->_epollServer->getCoroutinePoolSize(), this->_epollServer->getCoroutineStackSize()); - _scheduler->getEpoller()->setName("epoller-handle"); + //这种模式下, 为了保证当前线程能做和通信器结合, 必须也等在epoll上 + //因此当网络层收到数据, 写对队列后, 需要唤醒某一个handle的epoll, 从而唤醒某个协程 + _scheduler = TC_CoroutineScheduler::create(); + _scheduler->setPoolStackSize(this->_epollServer->getCoroutinePoolSize(), this->_epollServer->getCoroutineStackSize()); + _scheduler->getEpoller()->setName("epoller-handle"); - _dataBuffer->registerScheduler(_handleIndex, _scheduler); + _dataBuffer->registerScheduler(_handleIndex, _scheduler); - initialize(); + initialize(); - _scheduler->go(std::bind(&Handle::handleCoroutine, this)); + _scheduler->go(std::bind(&Handle::handleCoroutine, this)); - _epollServer->notifyThreadReady(); + _epollServer->notifyThreadReady(); - _scheduler->run(); + _scheduler->run(); - _dataBuffer->unregisterScheduler(_handleIndex); + _dataBuffer->unregisterScheduler(_handleIndex); + TC_CoroutineScheduler::reset(); } void TC_EpollServer::Handle::handleLoopThread() { - initialize(); + initialize(); - _epollServer->notifyThreadReady(); + _epollServer->notifyThreadReady(); - while (!_epollServer->isTerminate()) - { - _dataBuffer->wait(_handleIndex); + while (!_epollServer->isTerminate()) + { + _dataBuffer->wait(_handleIndex); - handleOnceThread(); - } + handleOnceThread(); + } } bool TC_EpollServer::Handle::allAdapterIsEmpty() { - if (_dataBuffer->getRecvBufferSize() > 0) { - return false; - } + if (_dataBuffer->getRecvBufferSize() > 0) { + return false; + } - return true; + return true; } bool TC_EpollServer::Handle::allFilterIsEmpty() { - return true; + return true; } void TC_EpollServer::Handle::notifyFilter() { - shared_ptr scheduler = _dataBuffer->getScheduler(this->_handleIndex); - - if (scheduler) - { - if(this->_epollServer->isTerminate()) - { - scheduler->terminate(); - } - else - { - scheduler->notify(); - } - } - else if(_netThread) - { - _netThread->notify(); - } - else - { - _dataBuffer->notifyBuffer(_handleIndex); - } + shared_ptr scheduler = _dataBuffer->getScheduler(this->_handleIndex); + + if (scheduler) + { + if(this->_epollServer->isTerminate()) + { + scheduler->terminate(); + } + else + { + scheduler->notify(); + } + } + else if(_netThread) + { + _netThread->notify(); + } + else + { + _dataBuffer->notifyBuffer(_handleIndex); + } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 服务连接 TC_EpollServer::Connection::Connection(const shared_ptr &connList, BindAdapter *pBindAdapter, int fd, const string& ip, uint16_t port, detail::LogInterface* logger) - : _connList(connList) - , _logger(logger) - , _pBindAdapter(pBindAdapter) - , _uid(0) - , _fd(fd) - , _ip(ip) - , _port(port) - , _iHeaderLen(0) - , _bClose(false) - , _bEmptyConn(true) + : _connList(connList) + , _logger(logger) + , _pBindAdapter(pBindAdapter) + , _uid(0) + , _fd(fd) + , _ip(ip) + , _port(port) + , _iHeaderLen(0) + , _bClose(false) + , _bEmptyConn(true) { - assert(fd != -1); + assert(fd != -1); - _iLastRefreshTime = TNOW; + _iLastRefreshTime = TNOW; } TC_EpollServer::Connection::Connection(const shared_ptr &connList, BindAdapter *pBindAdapter, int fd, detail::LogInterface *logger) - : _connList(connList) - , _logger(logger) - , _pBindAdapter(pBindAdapter) - , _uid(0) - , _fd(fd) - , _port(0) - , _iHeaderLen(0) - , _bClose(false) - , _bEmptyConn(false) /*udp is always false*/ + : _connList(connList) + , _logger(logger) + , _pBindAdapter(pBindAdapter) + , _uid(0) + , _fd(fd) + , _port(0) + , _iHeaderLen(0) + , _bClose(false) + , _bEmptyConn(false) /*udp is always false*/ { - // LOG_CONSOLE_DEBUG << endl; - _iLastRefreshTime = TNOW; + // LOG_CONSOLE_DEBUG << endl; + _iLastRefreshTime = TNOW; } TC_EpollServer::Connection::~Connection() { - // LOG_CONSOLE_DEBUG << endl; + // LOG_CONSOLE_DEBUG << endl; } void TC_EpollServer::Connection::initialize(TC_Epoller *epoller, unsigned int uid, NetThread *netThread) { - _uid = uid; + _uid = uid; - _netThread = netThread; + _netThread = netThread; - const TC_Endpoint &ep = _pBindAdapter->getEndpoint(); + const TC_Endpoint &ep = _pBindAdapter->getEndpoint(); #if TARS_SSL - if (ep.isSSL()) - { - _trans.reset(new TC_SSLTransceiver(epoller, ep)); - } - else if (ep.isTcp()) + if (ep.isSSL()) +{ + _trans.reset(new TC_SSLTransceiver(epoller, ep)); +} +else if (ep.isTcp()) +{ + _trans.reset(new TC_TCPTransceiver(epoller, ep)); +} +else +{ + _trans.reset(new TC_UDPTransceiver(epoller, ep)); +} +#else + if (ep.isUdp()) { - _trans.reset(new TC_TCPTransceiver(epoller, ep)); + _trans.reset(new TC_UDPTransceiver(epoller, ep)); } else { - _trans.reset(new TC_UDPTransceiver(epoller, ep)); + _trans.reset(new TC_TCPTransceiver(epoller, ep)); } -#else - if (ep.isUdp()) - { - _trans.reset(new TC_UDPTransceiver(epoller, ep)); - } - else - { - _trans.reset(new TC_TCPTransceiver(epoller, ep)); - } #endif - _trans->initializeServer(std::bind(&Connection::onCloseCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), - std::bind(&Connection::onRequestCallback, this, std::placeholders::_1), - std::bind(&Connection::onParserCallback, this, std::placeholders::_1, std::placeholders::_2), - std::bind(&Connection::onOpensslCallback, this, std::placeholders::_1), - TC_Transceiver::oncompletepackage_callback(), - std::bind(&Connection::onCompleteNetworkCallback, this, std::placeholders::_1)); + _trans->initializeServer(std::bind(&Connection::onCloseCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3), + std::bind(&Connection::onRequestCallback, this, std::placeholders::_1), + std::bind(&Connection::onParserCallback, this, std::placeholders::_1, std::placeholders::_2), + std::bind(&Connection::onOpensslCallback, this, std::placeholders::_1), + TC_Transceiver::oncompletepackage_callback(), + std::bind(&Connection::onCompleteNetworkCallback, this, std::placeholders::_1)); - _trans->setServerAuthCallback(_pBindAdapter->_onVerifyCallback); + _trans->setServerAuthCallback(_pBindAdapter->_onVerifyCallback); - _trans->getRecvBuffer().setConnection(this); + _trans->getRecvBuffer().setConnection(this); } bool TC_EpollServer::Connection::handleOutputImp(const shared_ptr &data) { // LOG_CONSOLE_DEBUG << endl; - TC_EpollServer::NetThread *netThread = (TC_EpollServer::NetThread *)data->cookie(); + TC_EpollServer::NetThread *netThread = (TC_EpollServer::NetThread *)data->cookie(); - int ret = 0; - try - { - ret = sendBuffer(); - } - catch(const std::exception& ex) - { - // LOG_CONSOLE_DEBUG << ex.what() << endl; - ret = -1; - _logger->error(ex.what()); - } + int ret = 0; + try + { + ret = sendBuffer(); + } + catch(const std::exception& ex) + { + // LOG_CONSOLE_DEBUG << ex.what() << endl; + ret = -1; + _logger->error(ex.what()); + } - if (ret < 0) - { - netThread->delConnection(this, true, (ret == -1) ? EM_CLIENT_CLOSE : EM_SERVER_CLOSE); + if (ret < 0) + { + netThread->delConnection(this, true, (ret == -1) ? EM_CLIENT_CLOSE : EM_SERVER_CLOSE); - return false; - } + return false; + } - auto cl = _connList.lock(); - if(cl) - { - cl->refresh(getId(), getTimeout() + TNOW); - } + auto cl = _connList.lock(); + if(cl) + { + cl->refresh(getId(), getTimeout() + TNOW); + } - return true; + return true; } bool TC_EpollServer::Connection::handleInputImp(const shared_ptr &data) { - TC_EpollServer::NetThread *netThread = (TC_EpollServer::NetThread *)data->cookie(); - - try - { - bool bRet = _trans->doResponse(); - if(false == bRet) - { - netThread->delConnection(this, true, EM_CLIENT_CLOSE); - return false; - } - } - catch(const std::exception& ex) - { - // LOG_CONSOLE_DEBUG << ex.what() << endl; - _logger->error(ex.what()); - netThread->delConnection(this, true, EM_CLIENT_CLOSE); - return false; - } - - auto cl = _connList.lock(); - if(cl) - { - cl->refresh(getId(), getTimeout() + TNOW); - } - - return true; +// LOG_CONSOLE_DEBUG << endl; + + TC_EpollServer::NetThread *netThread = (TC_EpollServer::NetThread *)data->cookie(); + + try + { + bool bRet = _trans->doResponse(); + if(false == bRet) + { + netThread->delConnection(this, true, EM_CLIENT_CLOSE); + return false; + } + } + catch(const std::exception& ex) + { + // LOG_CONSOLE_DEBUG << ex.what() << endl; + _logger->error(ex.what()); + netThread->delConnection(this, true, EM_CLIENT_CLOSE); + return false; + } + + auto cl = _connList.lock(); + if(cl) + { + cl->refresh(getId(), getTimeout() + TNOW); + } + + return true; } bool TC_EpollServer::Connection::handleCloseImp(const shared_ptr &data) { - // LOG_CONSOLE_DEBUG << endl; - TC_EpollServer::NetThread *netThread = (TC_EpollServer::NetThread *)data->cookie(); + // LOG_CONSOLE_DEBUG << endl; + TC_EpollServer::NetThread *netThread = (TC_EpollServer::NetThread *)data->cookie(); - netThread->delConnection(this, true, EM_SERVER_CLOSE); - return false; + netThread->delConnection(this, true, EM_SERVER_CLOSE); + return false; } void TC_EpollServer::Connection::registerEvent(TC_EpollServer::NetThread *netThread) { - shared_ptr epollInfo = _trans->bindFd(_fd); + shared_ptr epollInfo = _trans->bindFd(_fd); - epollInfo->cookie(netThread); + epollInfo->cookie(netThread); - map callbacks; + map callbacks; - callbacks[EPOLLIN] = std::bind(&TC_EpollServer::Connection::handleInputImp, this, std::placeholders::_1); - callbacks[EPOLLOUT] = std::bind(&TC_EpollServer::Connection::handleOutputImp, this, std::placeholders::_1); - callbacks[EPOLLERR] = std::bind(&TC_EpollServer::Connection::handleCloseImp, this, std::placeholders::_1); + callbacks[EPOLLIN] = std::bind(&TC_EpollServer::Connection::handleInputImp, this, std::placeholders::_1); + callbacks[EPOLLOUT] = std::bind(&TC_EpollServer::Connection::handleOutputImp, this, std::placeholders::_1); + callbacks[EPOLLERR] = std::bind(&TC_EpollServer::Connection::handleCloseImp, this, std::placeholders::_1); - // 回调 - if (this->isTcp() && this->_pBindAdapter->_epollServer->_acceptFunc != NULL) - { - try - { - this->_pBindAdapter->_epollServer->_acceptFunc(this); - } - catch(exception &ex) - { - _logger->error(string("accept callback error:") + ex.what()); - } - } + // 回调 + if (this->isTcp() && this->_pBindAdapter->_epollServer->_acceptFunc != NULL) + { + try + { + this->_pBindAdapter->_epollServer->_acceptFunc(this); + } + catch(exception &ex) + { + _logger->error(string("accept callback error:") + ex.what()); + } + } - epollInfo->registerCallback(callbacks, EPOLLIN | EPOLLOUT); + epollInfo->registerCallback(callbacks, EPOLLIN | EPOLLOUT); - //注意registerCallback, 网络线程马上关注网络事件, 并执行回调, 有可能由于_trans被释放了! + //注意registerCallback, 网络线程马上关注网络事件, 并执行回调, 有可能由于_trans被释放了! } void TC_EpollServer::Connection::close() { - _trans->close(); - // LOG_CONSOLE_DEBUG << _trans.use_count() << endl; + _trans->close(); + // LOG_CONSOLE_DEBUG << _trans.use_count() << endl; } void TC_EpollServer::Connection::onCloseCallback(TC_Transceiver *trans, TC_Transceiver::CloseReason reason, const string &err) { - _pBindAdapter->decreaseSendBufferSize(_messages.size()); + _pBindAdapter->decreaseSendBufferSize(_messages.size()); - if (trans->getEndpoint().isTcp() && trans->isValid()) - { - _pBindAdapter->decreaseSendBufferSize(); - } + if (trans->getEndpoint().isTcp() && trans->isValid()) + { + _pBindAdapter->decreaseSendBufferSize(); + } } std::shared_ptr TC_EpollServer::Connection::onOpensslCallback(TC_Transceiver* trans) { #if TARS_SSL - if(trans->isSSL()) { - assert(_pBindAdapter->_ctx); - return TC_OpenSSL::newSSL(_pBindAdapter->_ctx); - } - return NULL; + if(trans->isSSL()) { + assert(_pBindAdapter->_ctx); + return TC_OpenSSL::newSSL(_pBindAdapter->_ctx); +} +return NULL; #else - return NULL; + return NULL; #endif } void TC_EpollServer::Connection::onRequestCallback(TC_Transceiver *trans) { - while(!_messages.empty()) - { - auto it = _messages.begin(); + while(!_messages.empty()) + { + auto it = _messages.begin(); + +// LOG_CONSOLE_DEBUG << string((*it)->buffer()->buffer(), (*it)->buffer()->length()) << ", message:" << _messages.size() << endl; - TC_Transceiver::ReturnStatus iRet = _trans->sendRequest((*it)->buffer(), (*it)->getRecvContext()->addr()); + TC_Transceiver::ReturnStatus iRet = _trans->sendRequest((*it)->buffer(), (*it)->getRecvContext()->addr()); - if (iRet == TC_Transceiver::eRetError) - { - return; - } + if (iRet == TC_Transceiver::eRetError) + { + return; + } - if(iRet != TC_Transceiver::eRetNotSend) - { - _messageSize -= (*it)->buffer()->length(); + if(iRet != TC_Transceiver::eRetNotSend) + { + _messageSize -= (*it)->buffer()->length(); - _messages.erase(it); - } + _messages.erase(it); + } - //数据还不能发送 or 发送buffer已经满了 直接返回, 暂时不要再发送了! - if (iRet == TC_Transceiver::eRetNotSend || iRet == TC_Transceiver::eRetFull) - { - return; - } - } + //数据还不能发送 or 发送buffer已经满了 直接返回, 暂时不要再发送了! + if (iRet == TC_Transceiver::eRetNotSend || iRet == TC_Transceiver::eRetFull) + { + return; + } + } } TC_NetWorkBuffer::PACKET_TYPE TC_EpollServer::Connection::onParserCallback(TC_NetWorkBuffer& rbuf, TC_Transceiver *trans) { - if(rbuf.empty()) - { - return TC_NetWorkBuffer::PACKET_LESS; - } + if(rbuf.empty()) + { + return TC_NetWorkBuffer::PACKET_LESS; + } - //需要过滤首包包头 - if (_iHeaderLen > 0) { - if (rbuf.getBufferLength() >= (unsigned) _iHeaderLen) { - vector header; - rbuf.getHeader(_iHeaderLen, header); - _pBindAdapter->getHeaderFilterFunctor()(TC_NetWorkBuffer::PACKET_FULL, header); - rbuf.moveHeader(_iHeaderLen); - _iHeaderLen = 0; - } - else { - vector header = rbuf.getBuffers(); - _pBindAdapter->getHeaderFilterFunctor()(TC_NetWorkBuffer::PACKET_LESS, header); - _iHeaderLen -= (int) rbuf.getBufferLength(); - rbuf.clearBuffers(); - return TC_NetWorkBuffer::PACKET_LESS; - } - } + //需要过滤首包包头 + if (_iHeaderLen > 0) { + if (rbuf.getBufferLength() >= (unsigned) _iHeaderLen) { + vector header; + rbuf.getHeader(_iHeaderLen, header); + _pBindAdapter->getHeaderFilterFunctor()(TC_NetWorkBuffer::PACKET_FULL, header); + rbuf.moveHeader(_iHeaderLen); + _iHeaderLen = 0; + } + else { + vector header = rbuf.getBuffers(); + _pBindAdapter->getHeaderFilterFunctor()(TC_NetWorkBuffer::PACKET_LESS, header); + _iHeaderLen -= (int) rbuf.getBufferLength(); + rbuf.clearBuffers(); + return TC_NetWorkBuffer::PACKET_LESS; + } + } - rbuf.setConnection(this); + rbuf.setConnection(this); - vector ro; + vector ro; - TC_NetWorkBuffer::PACKET_TYPE ret = _pBindAdapter->getProtocol()(rbuf, ro); + TC_NetWorkBuffer::PACKET_TYPE ret = _pBindAdapter->getProtocol()(rbuf, ro); - if (ret == TC_NetWorkBuffer::PACKET_FULL) - { - auto recv = std::make_shared(_netThread->getIndex(), getId(), trans->getClientAddr(), getfd(), _pBindAdapter->shared_from_this()); + if (ret == TC_NetWorkBuffer::PACKET_FULL) + { + auto recv = std::make_shared(_netThread->getIndex(), getId(), trans->getClientAddr(), getfd(), _pBindAdapter->shared_from_this()); - recv->buffer().swap(ro); + recv->buffer().swap(ro); - //收到完整的包才算 - this->_bEmptyConn = false; + //收到完整的包才算 + this->_bEmptyConn = false; - _recv.push_back(recv); - //收到完整包 - // insertRecvQueue(recv); - } + _recv.push_back(recv); + //收到完整包 + // insertRecvQueue(recv); + } - return ret; + return ret; } void TC_EpollServer::Connection::onCompleteNetworkCallback(TC_Transceiver *trans) { - _pBindAdapter->insertRecvQueue(_recv); + _pBindAdapter->insertRecvQueue(_recv); - //收到完整包 - // insertRecvQueue(_recv); + //收到完整包 + // insertRecvQueue(_recv); - _recv.clear(); + _recv.clear(); } int TC_EpollServer::Connection::sendBufferDirect(const char* buff, size_t length) { - _pBindAdapter->increaseSendBufferSize(); + _pBindAdapter->increaseSendBufferSize(); - if(getBindAdapter()->getEndpoint().isTcp()) { + if(getBindAdapter()->getEndpoint().isTcp()) { - return _trans->sendRequest(std::make_shared(buff, length)); - } + return _trans->sendRequest(std::make_shared(buff, length)); + } - return 0; + return 0; } int TC_EpollServer::Connection::sendBufferDirect(const std::string& buff) { - return sendBufferDirect(buff.data(), buff.length()); + return sendBufferDirect(buff.data(), buff.length()); } int TC_EpollServer::Connection::sendBufferDirect(const shared_ptr& buff) { - _pBindAdapter->increaseSendBufferSize(); + _pBindAdapter->increaseSendBufferSize(); - if(getBindAdapter()->getEndpoint().isTcp()) { + if(getBindAdapter()->getEndpoint().isTcp()) { - return _trans->sendRequest(buff); - } + return _trans->sendRequest(buff); + } - return 0; + return 0; } int TC_EpollServer::Connection::checkFlow(TC_NetWorkBuffer& sendBuffer, size_t lastLeftBufferSize) @@ -828,169 +870,175 @@ int TC_EpollServer::Connection::checkFlow(TC_NetWorkBuffer& sendBuffer, size_t l // 每5秒检查一下积压情况, 连续12次(一分钟), 都是积压 // 且每个检查点, 积压长度都增加或者连续3次发送buffer字节小于1k, 就关闭连接, 主要避免极端情况 - //计算本次发送的大小: 上次没法送的数据大小 - 当前没发送的数据大小 - size_t nowSendBufferSize = lastLeftBufferSize - (_messageSize + sendBuffer.getBufferLength()); + //计算本次发送的大小: 上次没法送的数据大小 - 当前没发送的数据大小 + size_t nowSendBufferSize = lastLeftBufferSize - (_messageSize + sendBuffer.getBufferLength()); // 当出现队列积压的前提下, 且积压超过一定大小 // 每5秒检查一下积压情况, 连续12次(一分钟), 都是积压 // 且每个检查点, 积压长度都增加或者连续3次发送buffer字节小于1k, 就关闭连接, 主要避免极端情况 - size_t iBackPacketBuffLimit = _pBindAdapter->getBackPacketBuffLimit(); - if(iBackPacketBuffLimit > 0 && (_messageSize + sendBuffer.getBufferLength()) > iBackPacketBuffLimit) - { - if(_accumulateBufferSize == 0) - { - //开始积压 - _lastCheckTime = TNOW; - } - //累计本次发送数据(每5秒的数据累计到一起) - _accumulateBufferSize += nowSendBufferSize; - - if (TNOW - _lastCheckTime >= 5) - { - //如果持续有积压, 则每5秒检查一次 - _lastCheckTime = TNOW; - - //记录本次累计的数据<5秒内发送数据, 剩余未发送数据> - _checkSend.push_back(make_pair(_accumulateBufferSize, lastLeftBufferSize)); - - _accumulateBufferSize = 0; - - size_t iBackPacketBuffMin = _pBindAdapter->getBackPacketBuffMin(); - - //连续3个5秒, 发送速度都极慢, 每5秒发送 < iBackPacketBuffMin, 认为连接有问题, 关闭之 - int left = 3; - if ((int)_checkSend.size() >= left) - { - bool slow = true; - for (int i = (int)_checkSend.size() - 1; i >= (int)_checkSend.size() - left; i--) - { - //发送速度 - if (_checkSend[i].first > iBackPacketBuffMin) - { - slow = false; - continue; - } - } - - if (slow) - { - ostringstream os; - os << "send [" << _ip << ":" << _port << "] buffer queue send to slow, send size:"; - - for (int i = (int)_checkSend.size() - 1; i >= (int)(_checkSend.size() - left); i--) - { - os << ", " << _checkSend[i].first; - } - - _logger->error(os.str()); - sendBuffer.clearBuffers(); - return -5; - } - } - - //连续12个5秒, 都有积压现象, 检查 - if (_checkSend.size() >= 12) - { - bool accumulate = true; - for (size_t i = _checkSend.size() - 1; i >= 1; i--) { - //发送buffer 持续增加 - if (_checkSend[i].second < _checkSend[i - 1].second) { - accumulate = false; - break; - } - } - - //持续积压 - if (accumulate) - { - ostringstream os; - os << "send [" << _ip << ":" << _port << "] buffer queue continues to accumulate data, queue size:"; - - for (size_t i = 0; i < _checkSend.size(); i++) - { - os << ", " << _checkSend[i].second; - } - - _logger->error(os.str()); - sendBuffer.clearBuffers(); - return -4; - } - - _checkSend.erase(_checkSend.begin()); - } - } - } - else - { - //无积压 - _accumulateBufferSize = 0; - _lastCheckTime = TNOW; - _checkSend.clear(); - } - return 0; + size_t iBackPacketBuffLimit = _pBindAdapter->getBackPacketBuffLimit(); + if(iBackPacketBuffLimit > 0 && (_messageSize + sendBuffer.getBufferLength()) > iBackPacketBuffLimit) + { + if(_accumulateBufferSize == 0) + { + //开始积压 + _lastCheckTime = TNOW; + } + //累计本次发送数据(每5秒的数据累计到一起) + _accumulateBufferSize += nowSendBufferSize; + + if (TNOW - _lastCheckTime >= 5) + { + //如果持续有积压, 则每5秒检查一次 + _lastCheckTime = TNOW; + + //记录本次累计的数据<5秒内发送数据, 剩余未发送数据> + _checkSend.push_back(make_pair(_accumulateBufferSize, lastLeftBufferSize)); + + _accumulateBufferSize = 0; + + size_t iBackPacketBuffMin = _pBindAdapter->getBackPacketBuffMin(); + + //连续3个5秒, 发送速度都极慢, 每5秒发送 < iBackPacketBuffMin, 认为连接有问题, 关闭之 + int left = 3; + if ((int)_checkSend.size() >= left) + { + bool slow = true; + for (int i = (int)_checkSend.size() - 1; i >= (int)_checkSend.size() - left; i--) + { + //发送速度 + if (_checkSend[i].first > iBackPacketBuffMin) + { + slow = false; + continue; + } + } + + if (slow) + { + ostringstream os; + os << "send [" << _ip << ":" << _port << "] buffer queue send to slow, send size:"; + + for (int i = (int)_checkSend.size() - 1; i >= (int)(_checkSend.size() - left); i--) + { + os << ", " << _checkSend[i].first; + } + + _logger->error(os.str()); + sendBuffer.clearBuffers(); + return -5; + } + } + + //连续12个5秒, 都有积压现象, 检查 + if (_checkSend.size() >= 12) + { + bool accumulate = true; + for (size_t i = _checkSend.size() - 1; i >= 1; i--) { + //发送buffer 持续增加 + if (_checkSend[i].second < _checkSend[i - 1].second) { + accumulate = false; + break; + } + } + + //持续积压 + if (accumulate) + { + ostringstream os; + os << "send [" << _ip << ":" << _port << "] buffer queue continues to accumulate data, queue size:"; + + for (size_t i = 0; i < _checkSend.size(); i++) + { + os << ", " << _checkSend[i].second; + } + + _logger->error(os.str()); + sendBuffer.clearBuffers(); + return -4; + } + + _checkSend.erase(_checkSend.begin()); + } + } + } + else + { + //无积压 + _accumulateBufferSize = 0; + _lastCheckTime = TNOW; + _checkSend.clear(); + } + return 0; } int TC_EpollServer::Connection::sendBuffer() { - TC_NetWorkBuffer& sendBuffer = _trans->getSendBuffer(); + TC_NetWorkBuffer& sendBuffer = _trans->getSendBuffer(); + + //计算还有多少数据没有发送出去 + size_t lastLeftBufferSize = _messageSize + sendBuffer.getBufferLength(); - //计算还有多少数据没有发送出去 - size_t lastLeftBufferSize = _messageSize + sendBuffer.getBufferLength(); +// LOG_CONSOLE_DEBUG << "buff size:" << sendBuffer.getBufferLength() << ", " << sendBuffer.getBuffersString() << endl; - _trans->doRequest(); + _trans->doRequest(); - //需要关闭链接 - if (_bClose && _trans->getSendBuffer().empty()) - { - _logger->debug("send [" + _ip + ":" + TC_Common::tostr(_port) + "] close connection by user."); - return -2; - } + //需要关闭链接 + if (_bClose && _trans->getSendBuffer().empty()) + { + _logger->debug("send [" + _ip + ":" + TC_Common::tostr(_port) + "] close connection by user."); + return -2; + } - return checkFlow(sendBuffer, lastLeftBufferSize); + return checkFlow(sendBuffer, lastLeftBufferSize); } int TC_EpollServer::Connection::send(const shared_ptr &sc) { - assert(sc); + assert(sc); + + _pBindAdapter->increaseSendBufferSize(); + + //队列为空, 直接发送, 发送失败进队列 + //队列不为空, 直接进队列 + const shared_ptr& buff = sc->buffer(); - _pBindAdapter->increaseSendBufferSize(); +// LOG_CONSOLE_DEBUG << string(buff->buffer(), buff->length()) << ", message:" << _messages.size() << endl; - //队列为空, 直接发送, 发送失败进队列 - //队列不为空, 直接进队列 - const shared_ptr& buff = sc->buffer(); + if(_messages.empty()) + { + _trans->sendRequest(buff, sc->getRecvContext()->addr()); + } + + //网络句柄无效了, 返回-1, 上层会关闭连接 + if(!_trans->isValid()) + { + return -1; + } - if(_messages.empty()) - { - _trans->sendRequest(buff, sc->getRecvContext()->addr()); - } + //数据没有发送完 + if(!buff->empty()) + { + _messageSize += buff->length(); - //网络句柄无效了, 返回-1, 上层会关闭连接 - if(!_trans->isValid()) - { - return -1; - } + _messages.push_back(sc); + } - //数据没有发送完 - if(!buff->empty()) - { - _messageSize += sc->buffer()->length(); +// LOG_CONSOLE_DEBUG << "buff size:" << buff->length() << ", message:" << _messages.size() << endl; - _messages.push_back(sc); - } - auto cl = _connList.lock(); - if(cl) - { - cl->refresh(getId(), getTimeout() + TNOW); - } + if(cl) + { + cl->refresh(getId(), getTimeout() + TNOW); + } - return 0; + return 0; } void TC_EpollServer::Connection::setUdpRecvBuffer(size_t nSize) { - _trans->setUdpRecvBuffer(nSize); + _trans->setUdpRecvBuffer(nSize); } void TC_EpollServer::Connection::setUdpSendBuffer(size_t nSize) @@ -1000,49 +1048,49 @@ void TC_EpollServer::Connection::setUdpSendBuffer(size_t nSize) bool TC_EpollServer::Connection::setClose() { - _bClose = true; + _bClose = true; - return _trans->getSendBuffer().empty(); + return _trans->getSendBuffer().empty(); } //////////////////////////////////////////////////////////////// // TC_EpollServer::ConnectionList::ConnectionList(detail::LogInterface* logger) - : _emptyCheckTimeout(0) - , _logger(logger) - , _total(0) - , _free_size(0) - , _vConn(NULL) - , _lastTimeoutTime(0) - , _iConnectionMagic(0) + : _emptyCheckTimeout(0) + , _logger(logger) + , _total(0) + , _free_size(0) + , _vConn(NULL) + , _lastTimeoutTime(0) + , _iConnectionMagic(0) { } void TC_EpollServer::ConnectionList::init(uint32_t size, uint32_t iIndex) { - _lastTimeoutTime = TNOW; + _lastTimeoutTime = TNOW; - _total = size; + _total = size; - _free_size = 0; + _free_size = 0; - //初始化链接链表 - if (_vConn) delete[] _vConn; + //初始化链接链表 + if (_vConn) delete[] _vConn; - //分配total+1个空间(多分配一个空间, 第一个空间其实无效) - _vConn = new list_data[_total+1]; + //分配total+1个空间(多分配一个空间, 第一个空间其实无效) + _vConn = new list_data[_total+1]; - _iConnectionMagic = ((((uint32_t)TNOW) << 26) & (0xFFFFFFFF << 26)) + ((iIndex << 22) & (0xFFFFFFFF << 22));//((uint32_t)_lastTimeoutTime) << 20; + _iConnectionMagic = ((((uint32_t)TNOW) << 26) & (0xFFFFFFFF << 26)) + ((iIndex << 22) & (0xFFFFFFFF << 22));//((uint32_t)_lastTimeoutTime) << 20; - //free从1开始分配, 这个值为uid, 0保留为管道用, epollwait根据0判断是否是管道消息 - for(uint32_t i = 1; i <= _total; i++) - { - _vConn[i].first = NULL; + //free从1开始分配, 这个值为uid, 0保留为管道用, epollwait根据0判断是否是管道消息 + for(uint32_t i = 1; i <= _total; i++) + { + _vConn[i].first = NULL; - _free.push_back(i); + _free.push_back(i); - ++_free_size; - } + ++_free_size; + } // LOG_CONSOLE_DEBUG << this << ", " << "size:" << _free.size() << endl; @@ -1050,295 +1098,295 @@ void TC_EpollServer::ConnectionList::init(uint32_t size, uint32_t iIndex) void TC_EpollServer::ConnectionList::close() { - if(_vConn) - { - //服务停止时, 主动关闭一下连接, 这样客户端会检测到, 不需要等下一个发送包时, 发送失败才知道连接被关闭 - for (auto it = _tl.begin(); it != _tl.end(); ++it) { - if (_vConn[it->second].first != NULL) { - _vConn[it->second].first->close(); - delete _vConn[it->second].first; - _vConn[it->second].first = NULL; - } - } - _tl.clear(); - delete[] _vConn; - _vConn = NULL; - } + if(_vConn) + { + //服务停止时, 主动关闭一下连接, 这样客户端会检测到, 不需要等下一个发送包时, 发送失败才知道连接被关闭 + for (auto it = _tl.begin(); it != _tl.end(); ++it) { + if (_vConn[it->second].first != NULL) { + _vConn[it->second].first->close(); + delete _vConn[it->second].first; + _vConn[it->second].first = NULL; + } + } + _tl.clear(); + delete[] _vConn; + _vConn = NULL; + } } void TC_EpollServer::ConnectionList::closeConnections(weak_ptr bindAdapter) { - auto adapter = bindAdapter.lock(); + auto adapter = bindAdapter.lock(); - if(_vConn && adapter) - { - multimap tl = _tl; + if(_vConn && adapter) + { + multimap tl = _tl; - // LOG_CONSOLE_DEBUG << "list1 size:" << tl.size() << endl; + // LOG_CONSOLE_DEBUG << "list1 size:" << tl.size() << endl; - //服务停止时, 主动关闭一下连接, 这样客户端会检测到, 不需要等下一个发送包时, 发送失败才知道连接被关闭 - for (auto it = tl.begin(); it != tl.end(); ++it) - { - if (_vConn[it->second].first != NULL && _vConn[it->second].first->getBindAdapter() == adapter.get()) - { - this->delConnection(_vConn[it->second].first, true, TC_EpollServer::EM_SERVER_CLOSE); - } - } + //服务停止时, 主动关闭一下连接, 这样客户端会检测到, 不需要等下一个发送包时, 发送失败才知道连接被关闭 + for (auto it = tl.begin(); it != tl.end(); ++it) + { + if (_vConn[it->second].first != NULL && _vConn[it->second].first->getBindAdapter() == adapter.get()) + { + this->delConnection(_vConn[it->second].first, true, TC_EpollServer::EM_SERVER_CLOSE); + } + } - // LOG_CONSOLE_DEBUG << "list2 size:" << _tl.size() << endl; - } + // LOG_CONSOLE_DEBUG << "list2 size:" << _tl.size() << endl; + } } uint32_t TC_EpollServer::ConnectionList::getUniqId() { - TC_LockT lock(_mutex); + TC_LockT lock(_mutex); - assert(!_free.empty()); + assert(!_free.empty()); - uint32_t uid = _free.front(); + uint32_t uid = _free.front(); - assert(uid > 0 && uid <= _total); + assert(uid > 0 && uid <= _total); - _free.pop_front(); + _free.pop_front(); - --_free_size; + --_free_size; - return _iConnectionMagic | uid; + return _iConnectionMagic | uid; } TC_EpollServer::Connection* TC_EpollServer::ConnectionList::get(uint32_t uid) { - uint32_t magi = uid & (0xFFFFFFFF << 22); - uid = uid & (0x7FFFFFFF >> 9); + uint32_t magi = uid & (0xFFFFFFFF << 22); + uid = uid & (0x7FFFFFFF >> 9); - if (magi != _iConnectionMagic) return NULL; + if (magi != _iConnectionMagic) return NULL; - return _vConn[uid].first; + return _vConn[uid].first; } void TC_EpollServer::ConnectionList::add(Connection *cPtr, time_t iTimeOutStamp) { // LOG_CONSOLE_DEBUG << "add timeout:" << iTimeOutStamp << endl; - uint32_t muid = cPtr->getId(); - uint32_t magi = muid & (0xFFFFFFFF << 22); - uint32_t uid = muid & (0x7FFFFFFF >> 9); + uint32_t muid = cPtr->getId(); + uint32_t magi = muid & (0xFFFFFFFF << 22); + uint32_t uid = muid & (0x7FFFFFFF >> 9); - TC_LockT lock(_mutex); + TC_LockT lock(_mutex); - assert(magi == _iConnectionMagic && uid > 0 && uid <= _total && !_vConn[uid].first); + assert(magi == _iConnectionMagic && uid > 0 && uid <= _total && !_vConn[uid].first); - _vConn[uid] = make_pair(cPtr, _tl.insert(make_pair(iTimeOutStamp, uid))); + _vConn[uid] = make_pair(cPtr, _tl.insert(make_pair(iTimeOutStamp, uid))); } void TC_EpollServer::ConnectionList::refresh(uint32_t uid, time_t iTimeOutStamp) { - uint32_t magi = uid & (0xFFFFFFFF << 22); - uid = uid & (0x7FFFFFFF >> 9); + uint32_t magi = uid & (0xFFFFFFFF << 22); + uid = uid & (0x7FFFFFFF >> 9); - TC_LockT lock(_mutex); + TC_LockT lock(_mutex); - assert(magi == _iConnectionMagic && uid > 0 && uid <= _total && _vConn[uid].first); + assert(magi == _iConnectionMagic && uid > 0 && uid <= _total && _vConn[uid].first); - //至少一秒才刷新一次 - if(iTimeOutStamp - _vConn[uid].first->_iLastRefreshTime < 1) - { - return; - } + //至少一秒才刷新一次 + if(iTimeOutStamp - _vConn[uid].first->_iLastRefreshTime < 1) + { + return; + } - _vConn[uid].first->_iLastRefreshTime = iTimeOutStamp; + _vConn[uid].first->_iLastRefreshTime = iTimeOutStamp; - //删除超时链表 - _tl.erase(_vConn[uid].second); + //删除超时链表 + _tl.erase(_vConn[uid].second); - _vConn[uid].second = _tl.insert(make_pair(iTimeOutStamp, uid)); + _vConn[uid].second = _tl.insert(make_pair(iTimeOutStamp, uid)); } void TC_EpollServer::ConnectionList::delConnection(Connection *cPtr, bool bEraseList, EM_CLOSE_T closeType) { - assert(cPtr->isTcp()); + assert(cPtr->isTcp()); - BindAdapter* adapter = cPtr->getBindAdapter(); + BindAdapter* adapter = cPtr->getBindAdapter(); - //如果是TCP的连接才真正的关闭连接 - //false的情况,是超时被主动删除 - if(!bEraseList && _logger) - { - _logger->debug("timeout [" + cPtr->getIp() + ":" + TC_Common::tostr(cPtr->getPort()) + "] del from list"); - } + //如果是TCP的连接才真正的关闭连接 + //false的情况,是超时被主动删除 + if(!bEraseList && _logger) + { + _logger->debug("timeout [" + cPtr->getIp() + ":" + TC_Common::tostr(cPtr->getPort()) + "] del from list"); + } - uint32_t uid = cPtr->getId(); + uint32_t uid = cPtr->getId(); - //构造一个recv,通知业务该连接的关闭事件 - shared_ptr recv = std::make_shared(cPtr->getNetThread()->getIndex(), uid, cPtr->getTransceiver()->getClientAddr(), cPtr->getfd(), adapter->shared_from_this(), true, (int)closeType); + //构造一个recv,通知业务该连接的关闭事件 + shared_ptr recv = std::make_shared(cPtr->getNetThread()->getIndex(), uid, cPtr->getTransceiver()->getClientAddr(), cPtr->getfd(), adapter->shared_from_this(), true, (int)closeType); - adapter->insertRecvQueue(recv, true); + adapter->insertRecvQueue(recv, true); - //从epoller删除句柄放在close之前, 否则重用socket时会有问题 - cPtr->close(); + //从epoller删除句柄放在close之前, 否则重用socket时会有问题 + cPtr->close(); - //对于超时检查, 由于锁的原因, 在这里不从链表中删除 - if(bEraseList) - { - del(uid); - } + //对于超时检查, 由于锁的原因, 在这里不从链表中删除 + if(bEraseList) + { + del(uid); + } - adapter->decreaseNowConnection(); + adapter->decreaseNowConnection(); } void TC_EpollServer::ConnectionList::checkTimeout() { - time_t iCurTime = TNOW; + time_t iCurTime = TNOW; - //至少1s才能检查一次 - if(iCurTime - _lastTimeoutTime < 1) - { - return; - } + //至少1s才能检查一次 + if(iCurTime - _lastTimeoutTime < 1) + { + return; + } - _lastTimeoutTime = iCurTime; + _lastTimeoutTime = iCurTime; - TC_LockT lock(_mutex); + TC_LockT lock(_mutex); - multimap::iterator it = _tl.begin(); + multimap::iterator it = _tl.begin(); - while(it != _tl.end()) - { - //已经检查到当前时间点了, 后续不用在检查了 - if(it->first > iCurTime) - { - break; - } + while(it != _tl.end()) + { + //已经检查到当前时间点了, 后续不用在检查了 + if(it->first > iCurTime) + { + break; + } - uint32_t uid = it->second; + uint32_t uid = it->second; - ++it; + ++it; - //udp的监听端口, 不做处理 - if(_vConn[uid].first->isUdp()) - { - continue; - } + //udp的监听端口, 不做处理 + if(_vConn[uid].first->isUdp()) + { + continue; + } - //配置的超时间大于0, 才需要检查连接是否超时 - if(_vConn[uid].first->getTimeout() > 0) - { - //超时关闭 - delConnection(_vConn[uid].first, false, EM_SERVER_TIMEOUT_CLOSE); + //配置的超时间大于0, 才需要检查连接是否超时 + if(_vConn[uid].first->getTimeout() > 0) + { + //超时关闭 + delConnection(_vConn[uid].first, false, EM_SERVER_TIMEOUT_CLOSE); - //从链表中删除 - delNoLock(uid); - } - } + //从链表中删除 + delNoLock(uid); + } + } - if(_emptyCheckTimeout > 0) - { - it = _tl.begin(); - while(it != _tl.end()) - { - uint32_t uid = it->second; + if(_emptyCheckTimeout > 0) + { + it = _tl.begin(); + while(it != _tl.end()) + { + uint32_t uid = it->second; - //遍历所有的空连接 - if(_vConn[uid].first->isTcp() && _vConn[uid].first->isEmptyConn()) - { - //获取空连接的超时时间点 - time_t iEmptyTimeout = (it->first - _vConn[uid].first->getTimeout()) + _emptyCheckTimeout/1000; + //遍历所有的空连接 + if(_vConn[uid].first->isTcp() && _vConn[uid].first->isEmptyConn()) + { + //获取空连接的超时时间点 + time_t iEmptyTimeout = (it->first - _vConn[uid].first->getTimeout()) + _emptyCheckTimeout/1000; - //已经检查到当前时间点了, 后续不用在检查了 - if(iEmptyTimeout > iCurTime) - { - break; - } + //已经检查到当前时间点了, 后续不用在检查了 + if(iEmptyTimeout > iCurTime) + { + break; + } - //超时关闭 - delConnection(_vConn[uid].first, false, EM_SERVER_TIMEOUT_CLOSE); + //超时关闭 + delConnection(_vConn[uid].first, false, EM_SERVER_TIMEOUT_CLOSE); - //从链表中删除 - delNoLock(uid); - } + //从链表中删除 + delNoLock(uid); + } - ++it; - } - } + ++it; + } + } } vector TC_EpollServer::ConnectionList::getConnStatus(int lfd) { - vector v; + vector v; - TC_LockT lock(_mutex); + TC_LockT lock(_mutex); - for(size_t i = 1; i <= _total; i++) - { - //是当前监听端口的连接 - if(_vConn[i].first != NULL && _vConn[i].first->isTcp() && _vConn[i].first->getBindAdapter()->getSocket().getfd() == lfd) //getListenfd() == lfd) - { - ConnStatus cs; + for(size_t i = 1; i <= _total; i++) + { + //是当前监听端口的连接 + if(_vConn[i].first != NULL && _vConn[i].first->isTcp() && _vConn[i].first->getBindAdapter()->getSocket().getfd() == lfd) //getListenfd() == lfd) + { + ConnStatus cs; - cs.iLastRefreshTime = _vConn[i].first->_iLastRefreshTime; - cs.ip = _vConn[i].first->getIp(); - cs.port = _vConn[i].first->getPort(); - cs.timeout = _vConn[i].first->getTimeout(); - cs.uid = _vConn[i].first->getId(); - cs.recvBufferSize = _vConn[i].first->getRecvBuffer().getBufferLength(); - cs.sendBufferSize = _vConn[i].first->getSendBuffer().getBufferLength(); + cs.iLastRefreshTime = _vConn[i].first->_iLastRefreshTime; + cs.ip = _vConn[i].first->getIp(); + cs.port = _vConn[i].first->getPort(); + cs.timeout = _vConn[i].first->getTimeout(); + cs.uid = _vConn[i].first->getId(); + cs.recvBufferSize = _vConn[i].first->getRecvBuffer().getBufferLength(); + cs.sendBufferSize = _vConn[i].first->getSendBuffer().getBufferLength(); - v.push_back(cs); - } - } + v.push_back(cs); + } + } - return v; + return v; } void TC_EpollServer::ConnectionList::del(uint32_t uid) { - TC_LockT lock(_mutex); + TC_LockT lock(_mutex); - uint32_t magi = uid & (0xFFFFFFFF << 22); - uid = uid & (0x7FFFFFFF >> 9); + uint32_t magi = uid & (0xFFFFFFFF << 22); + uid = uid & (0x7FFFFFFF >> 9); - assert(magi == _iConnectionMagic && uid > 0 && uid <= _total && _vConn[uid].first); + assert(magi == _iConnectionMagic && uid > 0 && uid <= _total && _vConn[uid].first); - delNoLock(uid); + delNoLock(uid); } void TC_EpollServer::ConnectionList::delNoLock(uint32_t uid) { - assert(uid > 0 && uid <= _total && _vConn[uid].first); + assert(uid > 0 && uid <= _total && _vConn[uid].first); - _tl.erase(_vConn[uid].second); + _tl.erase(_vConn[uid].second); - Connection *conn = _vConn[uid].first; + Connection *conn = _vConn[uid].first; - _vConn[uid].first = NULL; + _vConn[uid].first = NULL; - delete conn; + delete conn; - _free.push_back(uid); + _free.push_back(uid); - ++_free_size; + ++_free_size; } /////////////////////////////BindAdapter/////////////////////////////////// TC_EpollServer::BindAdapter::BindAdapter(TC_EpollServer *epollServer) - : _pReportQueue(NULL) - , _pReportConRate(NULL) - , _pReportTimeoutNum(NULL) - , _epollServer(epollServer) - , _pf(echo_protocol) - , _hf(echo_header_filter) - , _name("") - , _iMaxConns(DEFAULT_MAX_CONN) - , _iCurConns(0) - , _iHandleNum(0) - , _eOrder(ALLOW_DENY) - , _iQueueCapacity(DEFAULT_QUEUE_CAP) - , _iQueueTimeout(DEFAULT_QUEUE_TIMEOUT) - , _iHeaderLen(0) - , _iHeartBeatTime(0) - , _protocolName("tars") + : _pReportQueue(NULL) + , _pReportConRate(NULL) + , _pReportTimeoutNum(NULL) + , _epollServer(epollServer) + , _pf(echo_protocol) + , _hf(echo_header_filter) + , _name("") + , _iMaxConns(DEFAULT_MAX_CONN) + , _iCurConns(0) + , _iHandleNum(0) + , _eOrder(ALLOW_DENY) + , _iQueueCapacity(DEFAULT_QUEUE_CAP) + , _iQueueTimeout(DEFAULT_QUEUE_TIMEOUT) + , _iHeaderLen(0) + , _iHeartBeatTime(0) + , _protocolName("tars") { } @@ -1350,337 +1398,337 @@ TC_EpollServer::BindAdapter::~BindAdapter() void TC_EpollServer::BindAdapter::bind() { - // try - // { + // try + // { - assert(!_s.isValid()); + assert(!_s.isValid()); #if TARGET_PLATFORM_WINDOWS - int type = _ep.isIPv6() ? AF_INET6 : AF_INET; + int type = _ep.isIPv6() ? AF_INET6 : AF_INET; #else - int type = _ep.isUnixLocal() ? AF_LOCAL : _ep.isIPv6() ? AF_INET6 : AF_INET; + int type = _ep.isUnixLocal() ? AF_LOCAL : _ep.isIPv6() ? AF_INET6 : AF_INET; #endif - int flag = 0; + int flag = 0; #if TARGET_PLATFORM_LINUX - flag = SOCK_CLOEXEC; + flag = SOCK_CLOEXEC; #endif - if (_ep.isTcp()) - { - _s.createSocket(SOCK_STREAM | flag, type); - } - else - { - _s.createSocket(SOCK_DGRAM | flag, type); - } + if (_ep.isTcp()) + { + _s.createSocket(SOCK_STREAM | flag, type); + } + else + { + _s.createSocket(SOCK_DGRAM | flag, type); + } #if TARGET_PLATFORM_WINDOWS - _s.bind(_ep.getHost(), _ep.getPort()); + _s.bind(_ep.getHost(), _ep.getPort()); #else - if (_ep.isUnixLocal()) - { - _s.bind(_ep.getHost().c_str()); - } - else - { - _s.bind(_ep.getHost(), _ep.getPort()); - } + if (_ep.isUnixLocal()) + { + _s.bind(_ep.getHost().c_str()); + } + else + { + _s.bind(_ep.getHost(), _ep.getPort()); + } #endif - if (_ep.isTcp()) - { - _s.listen(10240); + if (_ep.isTcp()) + { + _s.listen(10240); - try - { - //不要设置close wait否则http服务回包主动关闭连接会有问题 - _s.setNoCloseWait(); - _s.setKeepAlive(); - _s.setTcpNoDelay(); - } - catch(exception &ex) - { - } - } - _s.setblock(false); - // } - // catch(exception &ex) - // { - // _s.close(); - // cerr << "bind:" << _ep.toString() << " error:" << ex.what() << endl; - // throw ex; - // } + try + { + //不要设置close wait否则http服务回包主动关闭连接会有问题 + _s.setNoCloseWait(); + _s.setKeepAlive(); + _s.setTcpNoDelay(); + } + catch(exception &ex) + { + } + } + _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) { - _netThreads = netThreads; + _netThreads = netThreads; - for(auto netThread : _netThreads) - { - netThread->addAdapter(this); - } + for(auto netThread : _netThreads) + { + netThread->addAdapter(this); + } } void TC_EpollServer::BindAdapter::initUdp(NetThread* netThread) { - //对于udp, 网络线程监听所有监听的udp端口 - if(this->_ep.isUdp()) - { - Connection *cPtr = new Connection(netThread->getConnectionList(), this, _s.getfd(), _epollServer); + //对于udp, 网络线程监听所有监听的udp端口 + if(this->_ep.isUdp()) + { + Connection *cPtr = new Connection(netThread->getConnectionList(), this, _s.getfd(), _epollServer); - netThread->addUdpConnection(cPtr); + netThread->addUdpConnection(cPtr); - } + } } void TC_EpollServer::BindAdapter::setProtocolName(const string &name) { - std::lock_guard lock (_mutex); + std::lock_guard lock (_mutex); - _protocolName = name; + _protocolName = name; } const string &TC_EpollServer::BindAdapter::getProtocolName() { - std::lock_guard lock (_mutex); + std::lock_guard lock (_mutex); - return _protocolName; + return _protocolName; } bool TC_EpollServer::BindAdapter::isTarsProtocol() { - return (_protocolName == "tars" || _protocolName == "tars"); + return (_protocolName == "tars" || _protocolName == "tars"); } bool TC_EpollServer::BindAdapter::isIpAllow(const string &ip) const { - std::lock_guard lock (_mutex); - - if (_eOrder == ALLOW_DENY) - { - if (TC_Common::matchPeriod(ip, _vtAllow)) - { - return true; - } - if (TC_Common::matchPeriod(ip, _vtDeny)) - { - return false; - } - } - else - { - if (TC_Common::matchPeriod(ip, _vtDeny)) - { - return false; - } - if (TC_Common::matchPeriod(ip, _vtAllow)) - { - return true; - } - } - return _vtAllow.size() == 0; + std::lock_guard lock (_mutex); + + if (_eOrder == ALLOW_DENY) + { + if (TC_Common::matchPeriod(ip, _vtAllow)) + { + return true; + } + if (TC_Common::matchPeriod(ip, _vtDeny)) + { + return false; + } + } + else + { + if (TC_Common::matchPeriod(ip, _vtDeny)) + { + return false; + } + if (TC_Common::matchPeriod(ip, _vtAllow)) + { + return true; + } + } + return _vtAllow.size() == 0; } void TC_EpollServer::BindAdapter::enableManualListen() { - _manualListen = true; + _manualListen = true; } void TC_EpollServer::BindAdapter::manualListen() { - if(!this->getSocket().isValid() && !_epollServer->isTerminate()) - { - weak_ptr weakPtr = shared_from_this(); + if(!this->getSocket().isValid() && !_epollServer->isTerminate()) + { + weak_ptr weakPtr = shared_from_this(); - auto func = std::bind(&TC_EpollServer::listenCallback, _epollServer, weakPtr); + auto func = std::bind(&TC_EpollServer::listenCallback, _epollServer, weakPtr); - _epollServer->getEpoller()->asyncCallback(func); - } + _epollServer->getEpoller()->asyncCallback(func); + } } void TC_EpollServer::BindAdapter::cancelListen() { - if(this->getSocket().isValid() && !_epollServer->isTerminate()) - { - weak_ptr weakPtr = shared_from_this(); + if(this->getSocket().isValid() && !_epollServer->isTerminate()) + { + weak_ptr weakPtr = shared_from_this(); - auto func = std::bind(&TC_EpollServer::listenCallback, _epollServer, weakPtr); + auto func = std::bind(&TC_EpollServer::listenCallback, _epollServer, weakPtr); - _epollServer->getEpoller()->asyncCallback(func); - } + _epollServer->getEpoller()->asyncCallback(func); + } } void TC_EpollServer::BindAdapter::insertRecvQueue(const shared_ptr &recv, bool force) { - int iRet = isOverloadorDiscard(); + int iRet = isOverloadorDiscard(); - if (iRet == 0 || force) //未过载 - { - _dataBuffer->insertRecvQueue(recv); - } - else if (iRet == -1) //超过队列长度4/5,需要进行overload处理 - { - recv->setOverload(); + if (iRet == 0 || force) //未过载 + { + _dataBuffer->insertRecvQueue(recv); + } + else if (iRet == -1) //超过队列长度4/5,需要进行overload处理 + { + recv->setOverload(); - _dataBuffer->insertRecvQueue(recv); - } - else //接受队列满,需要丢弃 - { - _epollServer->error("[BindAdapter::insertRecvQueue] overload discard package"); - } + _dataBuffer->insertRecvQueue(recv); + } + else //接受队列满,需要丢弃 + { + _epollServer->error("[BindAdapter::insertRecvQueue] overload discard package"); + } } void TC_EpollServer::BindAdapter::insertRecvQueue(const deque> &recv) { - int iRet = isOverloadorDiscard(); + int iRet = isOverloadorDiscard(); - if (iRet == 0) //未过载 - { - _dataBuffer->insertRecvQueue(recv); - } - else if (iRet == -1) //超过队列长度4/5,需要进行overload处理 - { - for(auto r : recv) - { - r->setOverload(); - } + if (iRet == 0) //未过载 + { + _dataBuffer->insertRecvQueue(recv); + } + else if (iRet == -1) //超过队列长度4/5,需要进行overload处理 + { + for(auto r : recv) + { + r->setOverload(); + } - _dataBuffer->insertRecvQueue(recv); - } - else //接受队列满,需要丢弃 - { - _epollServer->error("[BindAdapter::insertRecvQueue] overload discard package"); - } + _dataBuffer->insertRecvQueue(recv); + } + else //接受队列满,需要丢弃 + { + _epollServer->error("[BindAdapter::insertRecvQueue] overload discard package"); + } } TC_NetWorkBuffer::PACKET_TYPE TC_EpollServer::BindAdapter::echo_protocol(TC_NetWorkBuffer &r, vector &o) { - o = r.getBuffers(); + o = r.getBuffers(); - r.clearBuffers(); + r.clearBuffers(); - return TC_NetWorkBuffer::PACKET_FULL; + return TC_NetWorkBuffer::PACKET_FULL; } TC_NetWorkBuffer::PACKET_TYPE TC_EpollServer::BindAdapter::echo_header_filter(TC_NetWorkBuffer::PACKET_TYPE i, vector &o) { - return TC_NetWorkBuffer::PACKET_FULL; + return TC_NetWorkBuffer::PACKET_FULL; } int TC_EpollServer::BindAdapter::isOverloadorDiscard() { - int iRecvBufferSize = _dataBuffer->getRecvBufferSize(); + int iRecvBufferSize = _dataBuffer->getRecvBufferSize(); - if(iRecvBufferSize > (int)(_iQueueCapacity / 5.*4) && (iRecvBufferSize < _iQueueCapacity) && (_iQueueCapacity > 0)) //overload - { - //超过队列4/5开始认为过载 - return -1; - } - else if(iRecvBufferSize > (int)(_iQueueCapacity) && _iQueueCapacity > 0 ) //队列满需要丢弃接受的数据包 - { - return -2; - } - return 0; + if(iRecvBufferSize > (int)(_iQueueCapacity / 5.*4) && (iRecvBufferSize < _iQueueCapacity) && (_iQueueCapacity > 0)) //overload + { + //超过队列4/5开始认为过载 + return -1; + } + else if(iRecvBufferSize > (int)(_iQueueCapacity) && _iQueueCapacity > 0 ) //队列满需要丢弃接受的数据包 + { + return -2; + } + return 0; } void TC_EpollServer::BindAdapter::setQueueTimeout(int t) { - if (t >= MIN_QUEUE_TIMEOUT) - { - _iQueueTimeout = t; - } - else - { - _iQueueTimeout = MIN_QUEUE_TIMEOUT; - } + if (t >= MIN_QUEUE_TIMEOUT) + { + _iQueueTimeout = t; + } + else + { + _iQueueTimeout = MIN_QUEUE_TIMEOUT; + } } void TC_EpollServer::BindAdapter::setProtocol(const TC_NetWorkBuffer::protocol_functor &pf, int iHeaderLen, const TC_EpollServer::header_filter_functor &hf) { - _pf = pf; + _pf = pf; - _hf = hf; + _hf = hf; - _iHeaderLen = iHeaderLen; + _iHeaderLen = iHeaderLen; } //////////////////////////////NetThread////////////////////////////////// TC_EpollServer::NetThread::NetThread(int threadIndex, TC_EpollServer *epollServer) - : _epoller(NULL) - , _threadIndex(threadIndex) - , _epollServer(epollServer) + : _epoller(NULL) + , _threadIndex(threadIndex) + , _epollServer(epollServer) // , _nUdpRecvBufferSize(DEFAULT_RECV_BUFFERSIZE) { - _list = std::make_shared(_epollServer); + _list = std::make_shared(_epollServer); } TC_EpollServer::NetThread::~NetThread() { - _list = NULL; + _list = NULL; } bool TC_EpollServer::NetThread::isReady() const { - return _scheduler && _scheduler->isReady(); + return _scheduler && _scheduler->isReady(); } void TC_EpollServer::NetThread::createEpoll(uint32_t maxAllConn) { - _list->init((uint32_t) maxAllConn, _threadIndex + 1); + _list->init((uint32_t) maxAllConn, _threadIndex + 1); } void TC_EpollServer::NetThread::delConnection(TC_EpollServer::Connection *cPtr, bool bEraseList, TC_EpollServer::EM_CLOSE_T closeType) { - if (cPtr->isTcp()) - { - _list->delConnection(cPtr, bEraseList, closeType); - } + if (cPtr->isTcp()) + { + _list->delConnection(cPtr, bEraseList, closeType); + } } void TC_EpollServer::NetThread::terminate() { - assert(_scheduler); + assert(_scheduler); - _scheduler->terminate(); + _scheduler->terminate(); } void TC_EpollServer::NetThread::notifyCloseConnectionList(const shared_ptr &adapter) { - weak_ptr wAdapter = adapter; + weak_ptr wAdapter = adapter; - auto func = std::bind(&TC_EpollServer::ConnectionList::closeConnections, _list, adapter); + auto func = std::bind(&TC_EpollServer::ConnectionList::closeConnections, _list, adapter); - _epoller->syncCallback(func); + _epoller->syncCallback(func); } void TC_EpollServer::NetThread::addTcpConnection(TC_EpollServer::Connection *cPtr) { - uint32_t uid = _list->getUniqId(); + uint32_t uid = _list->getUniqId(); - // LOG_CONSOLE_DEBUG << "uid:" << uid << endl; +// LOG_CONSOLE_DEBUG << "uid:" << uid << ", " << this->_threadIndex << endl; - cPtr->initialize(_epoller, uid, this); + cPtr->initialize(_epoller, uid, this); - _list->add(cPtr, cPtr->getTimeout() + TNOW); + _list->add(cPtr, cPtr->getTimeout() + TNOW); - cPtr->getBindAdapter()->increaseNowConnection(); + cPtr->getBindAdapter()->increaseNowConnection(); - //注意epoll add必须放在最后, 否则可能导致执行完, 才调用上面语句 - cPtr->registerEvent(this); + //注意epoll add必须放在最后, 否则可能导致执行完, 才调用上面语句 + cPtr->registerEvent(this); } void TC_EpollServer::NetThread::addUdpConnection(TC_EpollServer::Connection *cPtr) { - assert(_epoller != NULL); + assert(_epoller != NULL); - uint32_t uid = _list->getUniqId(); + uint32_t uid = _list->getUniqId(); - // LOG_CONSOLE_DEBUG << "uid:" << uid << endl; + // LOG_CONSOLE_DEBUG << "uid:" << uid << endl; - cPtr->initialize(_epoller, uid, this); + cPtr->initialize(_epoller, uid, this); //udp分配接收buffer cPtr->setUdpRecvBuffer(_epollServer->getUdpRecvBufferSize()); @@ -1688,174 +1736,178 @@ void TC_EpollServer::NetThread::addUdpConnection(TC_EpollServer::Connection *cPt _list->add(cPtr, cPtr->getTimeout() + TNOW); - cPtr->registerEvent(this); + cPtr->registerEvent(this); } void TC_EpollServer::NetThread::close(const shared_ptr & data) { - if(this->_epollServer->isTerminate()) - { - return; - } + if(this->_epollServer->isTerminate()) + { + return; + } - shared_ptr send = data->createCloseContext(); + shared_ptr send = data->createCloseContext(); - _sbuffer.push_back(send); + _sbuffer.push_back(send); // 通知epoll响应, 关闭连接 - notify(); + notify(); } void TC_EpollServer::NetThread::send(const shared_ptr & data) { - if(this->_epollServer->isTerminate()) - { - return; - } + if(this->_epollServer->isTerminate()) + { + return; + } - if(!_list) - { - //已经析构了! - return; - } + if(!_list) + { + //已经析构了! + return; + } - if (_threadId == TC_Thread::CURRENT_THREADID()) - { - //发送包线程和网络线程是同一个线程,直接发送即可 - Connection *cPtr = getConnectionPtr(data->uid()); + if (_threadId == TC_Thread::CURRENT_THREADID()) + { + //发送包线程和网络线程是同一个线程,直接发送即可 + Connection *cPtr = getConnectionPtr(data->uid()); - if (cPtr) - { - cPtr->send(data); - } - } - else - { - //发送包线程和网络线程不是同一个线程, 需要先放队列, 再唤醒网络线程去发送 - _sbuffer.push_back(data); + if (cPtr) + { + cPtr->send(data); + } + } + else + { + //发送包线程和网络线程不是同一个线程, 需要先放队列, 再唤醒网络线程去发送 + _sbuffer.push_back(data); - notify(); - } + notify(); + } } void TC_EpollServer::NetThread::processPipe() { - // LOG_CONSOLE("processPipe"); - - while (!_sbuffer.empty()) - { - shared_ptr sc = _sbuffer.front(); - - _sbuffer.pop_front(); - - Connection *cPtr = getConnectionPtr(sc->uid()); - - if (!cPtr) - { - continue; - } - - switch (sc->cmd()) - { - case 'c': - { - if (cPtr->setClose()) - { - delConnection(cPtr, true, EM_SERVER_CLOSE); - } - break; - } - case 's': - { - int ret = cPtr->send(sc); - if (ret < 0) - { - delConnection(cPtr, true, (ret == -1) ? EM_CLIENT_CLOSE : EM_SERVER_CLOSE); - } - break; - } - default: - assert(false); - } - } + // LOG_CONSOLE("processPipe"); + + while (!_sbuffer.empty()) + { + shared_ptr sc = _sbuffer.front(); + + _sbuffer.pop_front(); + + Connection *cPtr = getConnectionPtr(sc->uid()); + + if (!cPtr) + { + continue; + } + + switch (sc->cmd()) + { + case 'c': + { + if (cPtr->setClose()) + { + delConnection(cPtr, true, EM_SERVER_CLOSE); + } + break; + } + case 's': + { + int ret = cPtr->send(sc); + if (ret < 0) + { + delConnection(cPtr, true, (ret == -1) ? EM_CLIENT_CLOSE : EM_SERVER_CLOSE); + } + break; + } + default: + assert(false); + } + } } void TC_EpollServer::NetThread::setInitializeHandle(std::function initialize, std::function handle) { - _initialize = initialize; - _handle = handle; + _initialize = initialize; + _handle = handle; } void TC_EpollServer::NetThread::run() { - try - { - if(_epollServer->getOpenCoroutine() == NET_THREAD_QUEUE_HANDLES_THREAD || _epollServer->getOpenCoroutine() == NET_THREAD_MERGE_HANDLES_THREAD) - { - //线程模型, 此时调度器是local的, 线程里面无法感知到自己处于协程中 - _scheduler = std::make_shared(); - _scheduler->setPoolStackSize(10, 128*1024); + try + { + if(_epollServer->getOpenCoroutine() == NET_THREAD_QUEUE_HANDLES_THREAD || _epollServer->getOpenCoroutine() == NET_THREAD_MERGE_HANDLES_THREAD) + { + //线程模型, 此时调度器是local的, 线程里面无法感知到自己处于协程中 + _scheduler = std::make_shared(); + _scheduler->setPoolStackSize(10, 128*1024); - } - else - { - _scheduler = TC_CoroutineScheduler::create(); + } + else + { + _scheduler = TC_CoroutineScheduler::create(); - _scheduler->setPoolStackSize(_epollServer->getCoroutinePoolSize(), _epollServer->getCoroutineStackSize()); - } + _scheduler->setPoolStackSize(_epollServer->getCoroutinePoolSize(), _epollServer->getCoroutineStackSize()); + } - _epoller = _scheduler->getEpoller(); - _epoller->setName("net-thread"); + _epoller = _scheduler->getEpoller(); + _epoller->setName("net-thread"); - assert(_epoller); + assert(_epoller); - _threadId = TC_Thread::CURRENT_THREADID(); + _threadId = TC_Thread::CURRENT_THREADID(); - //对于udp, 网络线程监听所有监听的udp端口, 竞争收取数据 - for(auto adapter : _adapters) - { - adapter->initUdp(this); - } + //对于udp, 网络线程监听所有监听的udp端口, 竞争收取数据 + for(auto adapter : _adapters) + { + adapter->initUdp(this); + } - _epoller->postRepeated(2000, false, std::bind(&ConnectionList::checkTimeout, _list)); + _epoller->postRepeated(2000, false, std::bind(&ConnectionList::checkTimeout, _list)); - if(_initialize) - { - _initialize(); - } + if(_initialize) + { + _initialize(); + } - if(_handle) - { - _epoller->idle(_handle); - } + if(_handle) + { + _epoller->idle(_handle); + } - _epoller->idle(std::bind(&NetThread::processPipe, this)); + _epoller->idle(std::bind(&NetThread::processPipe, this)); - _epollServer->notifyThreadReady(); + _epollServer->notifyThreadReady(); - _scheduler->run(); + _scheduler->run(); - _list->close(); + _list->close(); - } - catch(const std::exception& ex) - { - _epollServer->error(ex.what()); - } - catch(...) - { - _epollServer->error("NetThread::run error"); - } + if(_epollServer->getOpenCoroutine() != NET_THREAD_QUEUE_HANDLES_THREAD && _epollServer->getOpenCoroutine() != NET_THREAD_MERGE_HANDLES_THREAD) + { + TC_CoroutineScheduler::reset(); + } + } + catch(const std::exception& ex) + { + _epollServer->error(ex.what()); + } + catch(...) + { + _epollServer->error("NetThread::run error"); + } } ///////////////////////////////////////////////////////////////////////////////////////////////////////// TC_EpollServer::TC_EpollServer(unsigned int iNetThreadNum) -: _threadNum(iNetThreadNum) -, _pLocalLogger(NULL) -, _acceptFunc(NULL) + : _threadNum(iNetThreadNum) + , _pLocalLogger(NULL) + , _acceptFunc(NULL) { #if TARGET_PLATFORM_WINDOWS - WSADATA wsadata; + WSADATA wsadata; WSAStartup(MAKEWORD(2, 2), &wsadata); #endif // @@ -1865,10 +1917,10 @@ WSAStartup(MAKEWORD(2, 2), &wsadata); TC_EpollServer::~TC_EpollServer() { - terminate(); + terminate(); #if TARGET_PLATFORM_WINDOWS - WSACleanup(); + WSACleanup(); #endif } @@ -1878,62 +1930,62 @@ void TC_EpollServer::applicationCallback(TC_EpollServer *epollServer) bool TC_EpollServer::accept(int fd, int domain) { - struct sockaddr_in stSockAddr4; - struct ::sockaddr_in6 stSockAddr6; + struct sockaddr_in stSockAddr4; + struct ::sockaddr_in6 stSockAddr6; - socklen_t iSockAddrSize = (AF_INET6 == domain) ? sizeof(::sockaddr_in6) : sizeof(sockaddr_in); - struct sockaddr *stSockAddr = (AF_INET6 == domain) ? (struct sockaddr *) &stSockAddr6 : (struct sockaddr *) &stSockAddr4; + socklen_t iSockAddrSize = (AF_INET6 == domain) ? sizeof(::sockaddr_in6) : sizeof(sockaddr_in); + struct sockaddr *stSockAddr = (AF_INET6 == domain) ? (struct sockaddr *) &stSockAddr6 : (struct sockaddr *) &stSockAddr4; - TC_Socket cs; + TC_Socket cs; - cs.setOwner(false); + cs.setOwner(false); - //接收连接 - TC_Socket s; + //接收连接 + TC_Socket s; - s.init(fd, false, domain); - int iRetCode = s.accept(cs, (struct sockaddr *) stSockAddr, iSockAddrSize); + s.init(fd, false, domain); + int iRetCode = s.accept(cs, (struct sockaddr *) stSockAddr, iSockAddrSize); - if (iRetCode > 0) - { - string ip; - uint16_t port; + if (iRetCode > 0) + { + string ip; + uint16_t port; - char sAddr[INET6_ADDRSTRLEN] = "\0"; + char sAddr[INET6_ADDRSTRLEN] = "\0"; - inet_ntop(domain, - (AF_INET6 == domain) ? (void *) &stSockAddr6.sin6_addr : (void *) &stSockAddr4.sin_addr, - sAddr, - sizeof(sAddr)); + inet_ntop(domain, + (AF_INET6 == domain) ? (void *) &stSockAddr6.sin6_addr : (void *) &stSockAddr4.sin_addr, + sAddr, + sizeof(sAddr)); - port = (AF_INET6 == domain) ? ntohs(stSockAddr6.sin6_port) : ntohs(stSockAddr4.sin_port); - ip = sAddr; + port = (AF_INET6 == domain) ? ntohs(stSockAddr6.sin6_port) : ntohs(stSockAddr4.sin_port); + ip = sAddr; - debug("accept [" + ip + ":" + TC_Common::tostr(port) + "] [" + TC_Common::tostr(cs.getfd()) + "] incomming"); + debug("accept [" + ip + ":" + TC_Common::tostr(port) + "] [" + TC_Common::tostr(cs.getfd()) + "] incomming"); - const BindAdapterPtr &adapter = _listeners[fd]; + const BindAdapterPtr &adapter = _listeners[fd]; - if (!adapter->isIpAllow(ip)) - { - debug("accept [" + ip + ":" + TC_Common::tostr(port) + "] [" + TC_Common::tostr(cs.getfd()) + "] not allowed"); + if (!adapter->isIpAllow(ip)) + { + debug("accept [" + ip + ":" + TC_Common::tostr(port) + "] [" + TC_Common::tostr(cs.getfd()) + "] not allowed"); - cs.close(); + cs.close(); - return true; - } + return true; + } - if (adapter->isLimitMaxConnection()) - { - error("accept [" + ip + ":" + TC_Common::tostr(port) + "][" + TC_Common::tostr(cs.getfd()) - + "] beyond max connection:" + TC_Common::tostr(_listeners[fd]->getMaxConns())); - cs.close(); + if (adapter->isLimitMaxConnection()) + { + error("accept [" + ip + ":" + TC_Common::tostr(port) + "][" + TC_Common::tostr(cs.getfd()) + + "] beyond max connection:" + TC_Common::tostr(_listeners[fd]->getMaxConns())); + cs.close(); - return true; - } + return true; + } - // LOG_CONSOLE_DEBUG << "fd:" << fd << ", cfd:" << cs.getfd() << endl; +// cou<< "fd:" << fd << ", cfd:" << cs.getfd() << endl; - cs.setblock(false); + cs.setblock(false); try { @@ -1946,623 +1998,634 @@ bool TC_EpollServer::accept(int fd, int domain) error("accept [" + ip + ":" + TC_Common::tostr(port) + "] set keep alive error:" + string(ex.what())); } - const std::vector &netThreads = adapter->getNetThreads(); + const std::vector &netThreads = adapter->getNetThreads(); - NetThread *netThread = netThreads[cs.getfd() % netThreads.size()]; + NetThread *netThread = netThreads[cs.getfd() % netThreads.size()]; - Connection *cPtr = new Connection(netThread->getConnectionList(), adapter.get(), cs.getfd(), ip, port, this); + Connection *cPtr = new Connection(netThread->getConnectionList(), adapter.get(), cs.getfd(), ip, port, this); - //过滤连接首个数据包包头 - cPtr->setHeaderFilterLen((int) adapter->getHeaderFilterLen()); + //过滤连接首个数据包包头 + cPtr->setHeaderFilterLen((int) adapter->getHeaderFilterLen()); - netThread->addTcpConnection(cPtr); + netThread->addTcpConnection(cPtr); - return true; - } - // else - // { - // //直到发生EAGAIN才不继续accept - // if (TC_Socket::isPending()) - // { - // return false; - // } - // } - // return true; - return false; + return true; + } + // else + // { + // //直到发生EAGAIN才不继续accept + // if (TC_Socket::isPending()) + // { + // return false; + // } + // } + // return true; + return false; } bool TC_EpollServer::acceptCallback(const shared_ptr &info, weak_ptr adapterPtr) { - auto adapter = adapterPtr.lock(); + auto adapter = adapterPtr.lock(); - if(!adapter) - { - return false; - } + if(!adapter) + { + return false; + } #if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS - bool ret; + bool ret; do { ret = accept(info->fd(), adapter->getEndpoint().isIPv6() ? AF_INET6 : AF_INET); - } while (ret); + } while (ret); #else - accept(info->fd(), adapter->_ep.isIPv6() ? AF_INET6 : AF_INET); + accept(info->fd(), adapter->_ep.isIPv6() ? AF_INET6 : AF_INET); #endif - return true; + return true; } void TC_EpollServer::listenCallback(weak_ptr adapterPtr) { // LOG_CONSOLE_DEBUG << endl; - auto adapter = adapterPtr.lock(); + auto adapter = adapterPtr.lock(); - if(!adapter) - { - return ; - } + if(!adapter) + { + return ; + } - if(!adapter->getSocket().isValid()) - { - //socket还没有开启, 则表示需要绑定 - adapter->bind(); + if(!adapter->getSocket().isValid()) + { + //socket还没有开启, 则表示需要绑定 + adapter->bind(); - int fd = adapter->getSocket().getfd(); + int fd = adapter->getSocket().getfd(); - _listeners[fd] = adapter; + _listeners[fd] = adapter; - // assert(!adapter->getEpollInfo()); + // assert(!adapter->getEpollInfo()); - auto info = _epoller->createEpollInfo(fd); + auto info = _epoller->createEpollInfo(fd); - adapter->setEpollInfo(info); + adapter->setEpollInfo(info); - map callbacks; + map callbacks; - callbacks[EPOLLIN] = std::bind(&TC_EpollServer::acceptCallback, this, std::placeholders::_1, adapter); + callbacks[EPOLLIN] = std::bind(&TC_EpollServer::acceptCallback, this, std::placeholders::_1, adapter); - adapter->getEpollInfo()->registerCallback(callbacks, EPOLLIN); + adapter->getEpollInfo()->registerCallback(callbacks, EPOLLIN); - this->info("bind adatper:" + adapter->getName()); + this->info("bind adatper:" + adapter->getName()); - } - else - { - //已经绑定中的, 则取消绑定 - int bindFd = adapter->getSocket().getfd(); + } + else + { + //已经绑定中的, 则取消绑定 + int bindFd = adapter->getSocket().getfd(); - _listeners.erase(bindFd); + _listeners.erase(bindFd); - adapter->getSocket().close(); + adapter->getSocket().close(); - //通知线程关闭和BindAdapter相关的连接 - for(auto nt : this->_netThreads) - { - nt->notifyCloseConnectionList(adapter); - } + //通知线程关闭和BindAdapter相关的连接 + for(auto nt : this->_netThreads) + { + nt->notifyCloseConnectionList(adapter); + } - _epoller->releaseEpollInfo(adapter->getEpollInfo()); + _epoller->releaseEpollInfo(adapter->getEpollInfo()); - adapter->getEpollInfo().reset(); + adapter->getEpollInfo().reset(); - info("un bind adatper:" + adapter->getName()); - } + info("un bind adatper:" + adapter->getName()); + } } void TC_EpollServer::waitForShutdown() { - _epoller = new TC_Epoller(); - _epoller->create(10240); - _epoller->setName("epollserver-epoller"); + _epoller = new TC_Epoller(); + _epoller->create(10240); + _epoller->setName("epollserver-epoller"); + + _readyThreadNum = 0; - _readyThreadNum = 0; + initHandle(); - initHandle(); + createEpoll(); - createEpoll(); + startHandle(); - startHandle(); + if(_hf) + { + _epoller->postRepeated(5000, false, [&](){ _hf(this);}); + } - if(_hf) - { - _epoller->postRepeated(5000, false, [&](){ _hf(this);}); - } + for(auto it : _bindAdapters) + { + if(it->getEndpoint().isTcp()) + { + if(it->getSocket().isValid()) + { + //socket有效, 说明已经绑定了, 注册accept回调 + shared_ptr info = _epoller->createEpollInfo(it->getSocket().getfd()); - for(auto it : _bindAdapters) - { - if(it->getEndpoint().isTcp()) - { - if(it->getSocket().isValid()) - { - //socket有效, 说明已经绑定了, 注册accept回调 - shared_ptr info = _epoller->createEpollInfo(it->getSocket().getfd()); + it->setEpollInfo(info); - it->setEpollInfo(info); + map callbacks; - map callbacks; + callbacks[EPOLLIN] = std::bind(&TC_EpollServer::acceptCallback, this, std::placeholders::_1, it); - callbacks[EPOLLIN] = std::bind(&TC_EpollServer::acceptCallback, this, std::placeholders::_1, it); + info->registerCallback(callbacks, EPOLLIN); + } + } + } - info->registerCallback(callbacks, EPOLLIN); - } - } - } + //等待协程调度器都启动, 否则有网络连接上时会出问题! + waitForReady(); - //等待协程调度器都启动, 否则有网络连接上时会出问题! - waitForReady(); + _epoller->loop(10000); - _epoller->loop(10000); + _epoller->clear(); - _epoller->clear(); + //停掉处理线程 + stopThread(); - //停掉处理线程 - stopThread(); + //关闭监听端口 + auto it = _listeners.begin(); + while(it != _listeners.end()) + { + if(it->second->getEndpoint().isTcp()) + { + _epoller->releaseEpollInfo(it->second->getEpollInfo()); + } - //关闭监听端口 - auto it = _listeners.begin(); - while(it != _listeners.end()) - { - if(it->second->getEndpoint().isTcp()) - { - _epoller->releaseEpollInfo(it->second->getEpollInfo()); - } + TC_Port::closeSocket(it->first); - TC_Port::closeSocket(it->first); + ++it; + } + _listeners.clear(); - ++it; - } - _listeners.clear(); + //回调 + if(_qf) + { + try + { + _qf(this); + } + catch (exception& ex) + { + } + } - //回调 - if(_qf) - { - try - { - _qf(this); - } - catch (exception& ex) - { - } - } + //删除网络线程 + for (size_t i = 0; i < _netThreads.size(); ++i) + { + delete _netThreads[i]; + } - //删除网络线程 - for (size_t i = 0; i < _netThreads.size(); ++i) - { - delete _netThreads[i]; - } + _netThreads.clear(); - _netThreads.clear(); + for (auto & bindAdapter : _bindAdapters) + { + bindAdapter->getHandles().clear(); + } - delete _epoller; + delete _epoller; - _epoller = NULL; + _epoller = NULL; - std::unique_lock lock(_readyMutex); + std::unique_lock lock(_readyMutex); - _readyThreadNum = 0; + _readyThreadNum = 0; - _readyCond.notify_all(); + _readyCond.notify_all(); } void TC_EpollServer::terminate() { - if(_epoller == NULL || _epoller->isTerminate()) - { - return; - } + if(_epoller == NULL || _epoller->isTerminate()) + { + return; + } - //先停止网络线程 - _epoller->terminate(); + //先停止网络线程 + _epoller->terminate(); - //等待waitForShutdown退出! - std::unique_lock lock(_readyMutex); - _readyCond.wait(lock, [&]{ - return _readyThreadNum == 0; - }); + //等待waitForShutdown退出! + std::unique_lock lock(_readyMutex); + _readyCond.wait(lock, [&]{ + return _readyThreadNum == 0; + }); } void TC_EpollServer::setEmptyConnTimeout(int timeout) { - for (size_t i = 0; i < _netThreads.size(); ++i) { - _netThreads[i]->setEmptyConnTimeout(timeout); - } + for (size_t i = 0; i < _netThreads.size(); ++i) { + _netThreads[i]->setEmptyConnTimeout(timeout); + } } int TC_EpollServer::bind(BindAdapterPtr & lsPtr) { - auto it = _listeners.begin(); + auto it = _listeners.begin(); - while (it != _listeners.end()) - { - if (it->second->getName() == lsPtr->getName()) - { - throw TC_Exception("bind name '" + lsPtr->getName() + "' conflicts."); - } - ++it; - } + while (it != _listeners.end()) + { + if (it->second->getName() == lsPtr->getName()) + { + throw TC_Exception("bind name '" + lsPtr->getName() + "' conflicts."); + } + ++it; + } - if(!lsPtr->isManualListen()) - { - lsPtr->bind(); + if(!lsPtr->isManualListen()) + { + lsPtr->bind(); - _listeners[lsPtr->getSocket().getfd()] = lsPtr; - } + _listeners[lsPtr->getSocket().getfd()] = lsPtr; + } - _bindAdapters.push_back(lsPtr); + _bindAdapters.push_back(lsPtr); - return lsPtr->getSocket().getfd(); + return lsPtr->getSocket().getfd(); } void TC_EpollServer::initHandle() { - if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_THREAD || _openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_CO) - { - //网路线程独立, 通过队列和处理线程交互数据 - //不同的连接丢给不同的网路线程处理 - //网络线程接收数据, 丢给对应adapter的队列, 处理线程/协程竞争数据 - for (int i = 0; i < _threadNum; ++i) - { - NetThread *netThread = new NetThread(i, this); - - _netThreads.push_back(netThread); - } - - for (auto & bindAdapter : _bindAdapters) - { - bindAdapter->setNetThreads(_netThreads); - } - - //启动handle线程 - for (auto & bindAdapter : _bindAdapters) - { - const vector & hds = bindAdapter->getHandles(); - - for (uint32_t i = 0; i < hds.size(); ++i) - { - hds[i]->setDataBuffer(bindAdapter->getDataBuffer()); - } - } - - } - else if(_openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO || _openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD) - { - //网络线程和处理线程是同一个线程(一对一) - //不同的连接丢给不同的网路线程处理 - for (auto & bindAdapter : _bindAdapters) - { - vector & hds = bindAdapter->getHandles(); - - vector adapterNetThreads; - - for (uint32_t i = 0; i < hds.size(); ++i) - { - //注意net thread是和adapter相关, 索引每个adapter从头计算 - NetThread *netThread = new NetThread(i, this); - - _netThreads.push_back(netThread); - - adapterNetThreads.push_back(netThread); - - hds[i]->setDataBuffer(bindAdapter->getDataBuffer()); - hds[i]->setNetThread(netThread); - - if(_openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO) - { - netThread->setInitializeHandle(std::bind(&Handle::initialize, hds[i]), std::bind(&Handle::handleOnceCoroutine, hds[i])); - } - else if(_openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD) - { - netThread->setInitializeHandle(std::bind(&Handle::initialize, hds[i]), std::bind(&Handle::handleOnceThread, hds[i])); - } - } - - bindAdapter->setNetThreads(adapterNetThreads); - } - } - else - { - error("please check server pattern, exit!"); - exit(-1); - } + if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_THREAD || _openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_CO) + { + //网路线程独立, 通过队列和处理线程交互数据 + //不同的连接丢给不同的网路线程处理 + //网络线程接收数据, 丢给对应adapter的队列, 处理线程/协程竞争数据 + for (int i = 0; i < _threadNum; ++i) + { + NetThread *netThread = new NetThread(i, this); + + _netThreads.push_back(netThread); + } + + for (auto & bindAdapter : _bindAdapters) + { + bindAdapter->setNetThreads(_netThreads); + } + + //启动handle线程 + for (auto & bindAdapter : _bindAdapters) + { + const vector & hds = bindAdapter->getHandles(); + + for (uint32_t i = 0; i < hds.size(); ++i) + { + hds[i]->setDataBuffer(bindAdapter->getDataBuffer()); + } + } + + } + else if(_openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO || _openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD) + { + //网络线程和处理线程是同一个线程(一对一) + //不同的连接丢给不同的网路线程处理 + for (auto & bindAdapter : _bindAdapters) + { + vector & hds = bindAdapter->getHandles(); + + vector adapterNetThreads; + + for (uint32_t i = 0; i < hds.size(); ++i) + { + //注意net thread是和adapter相关, 索引每个adapter从头计算 + NetThread *netThread = new NetThread(i, this); + + _netThreads.push_back(netThread); + + adapterNetThreads.push_back(netThread); + + hds[i]->setDataBuffer(bindAdapter->getDataBuffer()); + hds[i]->setNetThread(netThread); + + if(_openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO) + { + netThread->setInitializeHandle(std::bind(&Handle::initialize, hds[i]), std::bind(&Handle::handleOnceCoroutine, hds[i])); + } + else if(_openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD) + { + netThread->setInitializeHandle(std::bind(&Handle::initialize, hds[i]), std::bind(&Handle::handleOnceThread, hds[i])); + } + } + + bindAdapter->setNetThreads(adapterNetThreads); + } + } + else + { + error("please check server pattern, exit!"); + exit(-1); + } } void TC_EpollServer::startHandle() { - if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_THREAD || _openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_CO) - { - for (size_t i = 0; i < _netThreads.size(); ++i) - { - _netThreads[i]->start(); - } + if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_THREAD || _openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_CO) + { + for (size_t i = 0; i < _netThreads.size(); ++i) + { + _netThreads[i]->start(); + } // LOG_CONSOLE_DEBUG << "start thread:" << _netThreads.size() << endl; - int handleNum = 0; - - //启动handle线程 - for (auto & bindAdapter : _bindAdapters) - { - handleNum += bindAdapter->getHandleNum(); - - const vector & hds = bindAdapter->getHandles(); - - for (uint32_t i = 0; i < hds.size(); ++i) - { - if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_THREAD) - { - _handlePool.exec(std::bind(&Handle::handleLoopThread, hds[i])); - } - else if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_CO) - { - _handlePool.exec(std::bind(&Handle::handleLoopCoroutine, hds[i])); - } - } - } - - _handlePool.init(handleNum); - - _handlePool.start(); - } - else if(_openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO || _openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD) - { - //网络线程和处理线程是同一个线程(一对一) - //不同的连接丢给不同的网路线程处理 - for (auto & bindAdapter : _bindAdapters) - { - vector & hds = bindAdapter->getHandles(); - - for (uint32_t i = 0; i < hds.size(); ++i) - { - hds[i]->getNetThread()->start(); - } - } - } - else - { - error("please check server pattern, exit!"); - exit(-1); - } + int handleNum = 0; + + //启动handle线程 + for (auto & bindAdapter : _bindAdapters) + { + handleNum += bindAdapter->getHandleNum(); + + const vector & hds = bindAdapter->getHandles(); + + for (uint32_t i = 0; i < hds.size(); ++i) + { + if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_THREAD) + { + _handlePool.exec(std::bind(&Handle::handleLoopThread, hds[i])); + } + else if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_CO) + { + _handlePool.exec(std::bind(&Handle::handleLoopCoroutine, hds[i])); + } + } + } + + _handlePool.init(handleNum); + + _handlePool.start(); + } + else if(_openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_CO || _openCoroutine == TC_EpollServer::NET_THREAD_MERGE_HANDLES_THREAD) + { + //网络线程和处理线程是同一个线程(一对一) + //不同的连接丢给不同的网路线程处理 + for (auto & bindAdapter : _bindAdapters) + { + vector & hds = bindAdapter->getHandles(); + + for (uint32_t i = 0; i < hds.size(); ++i) + { + hds[i]->getNetThread()->start(); + } + } + } + else + { + error("please check server pattern, exit!"); + exit(-1); + } } void TC_EpollServer::notifyThreadReady() { - std::unique_lock lock(_readyMutex); + std::unique_lock lock(_readyMutex); - ++_readyThreadNum; + ++_readyThreadNum; - _readyCond.notify_all(); + _readyCond.notify_all(); } void TC_EpollServer::waitForReady() { - int readyThreadNum = 0; + int readyThreadNum = 0; - if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_THREAD || _openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_CO) - { - readyThreadNum = _threadNum; - } + if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_THREAD || _openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_CO) + { + readyThreadNum = _threadNum; + } - for (auto & bindAdapter : _bindAdapters) - { - const vector & hds = bindAdapter->getHandles(); + for (auto & bindAdapter : _bindAdapters) + { + const vector & hds = bindAdapter->getHandles(); - readyThreadNum += hds.size(); - } + readyThreadNum += hds.size(); + } - { - std::unique_lock lock(_readyMutex); - if(_readyThreadNum == readyThreadNum) - { - return; - } - _readyCond.wait(lock, [&]{ - return _readyThreadNum == readyThreadNum; - }); - } + { + std::unique_lock lock(_readyMutex); + if(_readyThreadNum == readyThreadNum) + { + return; + } + _readyCond.wait(lock, [&]{ + return _readyThreadNum == readyThreadNum; + }); + } } void TC_EpollServer::stopThread() { - if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_THREAD || _openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_CO) - { - //先停止网络线程(如果先停止处理线程/协程以后, 否则来了网络事件, 会导致crash) - for (size_t i = 0; i < _netThreads.size(); ++i) - { - if (_netThreads[i]->joinable()) - { - _netThreads[i]->terminate(); - - _netThreads[i]->getThreadControl().join(); - } - } - - //停止掉handle线程 - for (auto & bindAdapter : _bindAdapters) - { - const vector & hds = bindAdapter->getHandles(); - - for (uint32_t i = 0; i < hds.size(); ++i) - { - hds[i]->terminate(); - } - } - - _handlePool.stop(); - } - else - { - //合并网络线程和处理线程, 直接停止网络线程即可 - for (auto & bindAdapter : _bindAdapters) - { - const vector & hds = bindAdapter->getHandles(); - - for (uint32_t i = 0; i < hds.size(); ++i) - { - hds[i]->terminate(); - - if(hds[i]->getNetThread()->joinable()) - { - hds[i]->getNetThread()->terminate(); - hds[i]->getNetThread()->getThreadControl().join(); - } - } - } - } + if(_openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_THREAD || _openCoroutine == TC_EpollServer::NET_THREAD_QUEUE_HANDLES_CO) + { + //先停止网络线程(如果先停止处理线程/协程以后, 否则来了网络事件, 会导致crash) + for (size_t i = 0; i < _netThreads.size(); ++i) + { + if (_netThreads[i]->joinable()) + { + _netThreads[i]->terminate(); + } + } + + //停止掉handle线程 + for (auto & bindAdapter : _bindAdapters) + { + const vector & hds = bindAdapter->getHandles(); + + for (uint32_t i = 0; i < hds.size(); ++i) + { + hds[i]->terminate(); + } + } + + _handlePool.stop(); + + for (size_t i = 0; i < _netThreads.size(); ++i) + { + if (_netThreads[i]->joinable()) + { + _netThreads[i]->getThreadControl().join(); + } + } + } + else + { + //合并网络线程和处理线程, 直接停止网络线程即可 + for (auto & bindAdapter : _bindAdapters) + { + const vector & hds = bindAdapter->getHandles(); + + for (uint32_t i = 0; i < hds.size(); ++i) + { + hds[i]->terminate(); + + if(hds[i]->getNetThread()->joinable()) + { + hds[i]->getNetThread()->terminate(); + hds[i]->getNetThread()->getThreadControl().join(); + } + } + } + } } void TC_EpollServer::createEpoll() { - uint32_t maxAllConn = 0; + uint32_t maxAllConn = 0; - //监听socket + //监听socket // auto it = _listeners.begin(); - for (auto it : _bindAdapters) - { - if (it->getEndpoint().isTcp()) - { - maxAllConn += it->getMaxConns(); - } - else { - maxAllConn++; - } + for (auto it : _bindAdapters) + { + if (it->getEndpoint().isTcp()) + { + maxAllConn += it->getMaxConns(); + } + else { + maxAllConn++; + } // ++it; - } + } - if (maxAllConn >= (1 << 22)) { - error("createEpoll connection num: " + TC_Common::tostr(maxAllConn) + " >= " + TC_Common::tostr(1 << 22)); - maxAllConn = (1 << 22) - 1; - } + if (maxAllConn >= (1 << 22)) { + error("createEpoll connection num: " + TC_Common::tostr(maxAllConn) + " >= " + TC_Common::tostr(1 << 22)); + maxAllConn = (1 << 22) - 1; + } - for (size_t i = 0; i < _netThreads.size(); ++i) { - _netThreads[i]->createEpoll(maxAllConn); - } + for (size_t i = 0; i < _netThreads.size(); ++i) { + _netThreads[i]->createEpoll(maxAllConn); + } } TC_EpollServer::BindAdapterPtr TC_EpollServer::getBindAdapter(const string & sName) { - auto it = _bindAdapters.begin(); + auto it = _bindAdapters.begin(); - while (it != _bindAdapters.end()) - { - if ((*it)->getName() == sName) - { - return (*it); - } + while (it != _bindAdapters.end()) + { + if ((*it)->getName() == sName) + { + return (*it); + } - ++it; - } - return NULL; + ++it; + } + return NULL; } vector TC_EpollServer::getBindAdapters() { - return _bindAdapters; + return _bindAdapters; } void TC_EpollServer::close(const shared_ptr & data) { - auto adapter = data->adapter(); + auto adapter = data->adapter(); - if(adapter && !adapter->isUdp()) { - //非UDP模式下, close才有效 - adapter->getNetThread(data->threadIndex())->close(data); - } + if(adapter && !adapter->isUdp()) { + //非UDP模式下, close才有效 + adapter->getNetThread(data->threadIndex())->close(data); + } } void TC_EpollServer::send(const shared_ptr & data) { - if(data->buffer()->empty()) - return; + if(data->buffer()->empty()) + return; - auto adapter = data->getRecvContext()->adapter(); + auto adapter = data->getRecvContext()->adapter(); - if(adapter) - { - adapter->getNetThread(data->getRecvContext()->threadIndex())->send(data); - } + if(adapter) + { + adapter->getNetThread(data->getRecvContext()->threadIndex())->send(data); + } } void TC_EpollServer::debug(const string & s) const { - if (_pLocalLogger) { - _pLocalLogger->debug() << "[TARS]" << s << endl; - } + if (_pLocalLogger) { + _pLocalLogger->debug() << "[TARS]" << s << endl; + } } void TC_EpollServer::info(const string & s) const { - if (_pLocalLogger) { - _pLocalLogger->info() << "[TARS]" << s << endl; - } + if (_pLocalLogger) { + _pLocalLogger->info() << "[TARS]" << s << endl; + } } void TC_EpollServer::tars(const string & s) const { - if (_pLocalLogger) { - _pLocalLogger->tars() << "[TARS]" << s << endl; - } + if (_pLocalLogger) { + _pLocalLogger->tars() << "[TARS]" << s << endl; + } } void TC_EpollServer::error(const string & s) const { - if (_pLocalLogger) { - _pLocalLogger->error() << "[TARS]" << s << endl; - } + if (_pLocalLogger) { + _pLocalLogger->error() << "[TARS]" << s << endl; + } } vector TC_EpollServer::getConnStatus(int lfd) { - vector vConnStatus; - for (size_t i = 0; i < _netThreads.size(); ++i) { - vector tmp = _netThreads[i]->getConnStatus(lfd); - for (size_t k = 0; k < tmp.size(); ++k) { - vConnStatus.push_back(tmp[k]); - } - } - return vConnStatus; + vector vConnStatus; + for (size_t i = 0; i < _netThreads.size(); ++i) { + vector tmp = _netThreads[i]->getConnStatus(lfd); + for (size_t k = 0; k < tmp.size(); ++k) { + vConnStatus.push_back(tmp[k]); + } + } + return vConnStatus; } unordered_map TC_EpollServer::getListenSocketInfo() { - return _listeners; + return _listeners; } size_t TC_EpollServer::getConnectionCount() { - size_t iConnTotal = 0; - for (size_t i = 0; i < _netThreads.size(); ++i) { - iConnTotal += _netThreads[i]->getConnectionCount(); - } - return iConnTotal; + size_t iConnTotal = 0; + for (size_t i = 0; i < _netThreads.size(); ++i) { + iConnTotal += _netThreads[i]->getConnectionCount(); + } + return iConnTotal; } size_t TC_EpollServer::getLogicThreadNum() { - size_t iNum = 0; + size_t iNum = 0; - for (auto & bindAdapter : _bindAdapters) { - iNum += bindAdapter->getHandles().size(); - } - return iNum; + for (auto & bindAdapter : _bindAdapters) { + iNum += bindAdapter->getHandles().size(); + } + return iNum; } void TC_EpollServer::setOpenCoroutine(SERVER_OPEN_COROUTINE openCoroutine) { - if(openCoroutine >= NET_THREAD_QUEUE_HANDLES_THREAD && openCoroutine <= NET_THREAD_MERGE_HANDLES_CO) - { - _openCoroutine = openCoroutine; - } + if(openCoroutine >= NET_THREAD_QUEUE_HANDLES_THREAD && openCoroutine <= NET_THREAD_MERGE_HANDLES_CO) + { + _openCoroutine = openCoroutine; + } } void TC_EpollServer::setCoroutineStack(uint32_t iPoolSize, size_t iStackSize) { - _iCoroutinePoolSize = iPoolSize; - _iCoroutineStackSize = iStackSize; + _iCoroutinePoolSize = iPoolSize; + _iCoroutineStackSize = iStackSize; } } diff --git a/util/src/tc_epoller.cpp b/util/src/tc_epoller.cpp index f2e08296..23c2c945 100755 --- a/util/src/tc_epoller.cpp +++ b/util/src/tc_epoller.cpp @@ -309,6 +309,7 @@ void TC_Epoller::close() } #if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS +// LOG_CONSOLE_DEBUG << endl; ::close(_iEpollfd); _iEpollfd = -1; diff --git a/util/src/tc_gzip.cpp b/util/src/tc_gzip.cpp index e693a35e..8f1a43e1 100644 --- a/util/src/tc_gzip.cpp +++ b/util/src/tc_gzip.cpp @@ -16,7 +16,7 @@ #include "util/tc_gzip.h" -#if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS +#if TARS_GZIP #include #include diff --git a/util/src/tc_json.cpp b/util/src/tc_json.cpp index 5339c62e..ff99c952 100755 --- a/util/src/tc_json.cpp +++ b/util/src/tc_json.cpp @@ -1,6 +1,7 @@ #include "util/tc_json.h" -#include +#include +#include #include #include #include @@ -429,6 +430,7 @@ JsonValueNumPtr TC_Json::getNum(BufferJsonReader & reader,char head) { bOk=true; bExponential=(bool)(c-0x30); + iExponential=c-0x30; } else { diff --git a/util/src/tc_logger.cpp b/util/src/tc_logger.cpp index b2f8d96c..b7074935 100644 --- a/util/src/tc_logger.cpp +++ b/util/src/tc_logger.cpp @@ -33,7 +33,7 @@ static int __global_logger_debug_init__ = init_global_debug_log(); bool TC_LoggerRoll::_bDyeingFlag = false; TC_SpinLock TC_LoggerRoll::_mutexDyeing; -unordered_map TC_LoggerRoll::_mapThreadID; +unordered_map TC_LoggerRoll::_mapThreadID; const string LogByDay::FORMAT = "%Y%m%d"; const string LogByHour::FORMAT = "%Y%m%d%H"; diff --git a/util/src/tc_network_buffer.cpp b/util/src/tc_network_buffer.cpp index cdb89495..f5cc47c9 100755 --- a/util/src/tc_network_buffer.cpp +++ b/util/src/tc_network_buffer.cpp @@ -1,4 +1,4 @@ -/** +/** * Tencent is pleased to support the open source community by making Tars available. * * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved. diff --git a/util/src/tc_socket.cpp b/util/src/tc_socket.cpp index 7895d25d..f81946bf 100755 --- a/util/src/tc_socket.cpp +++ b/util/src/tc_socket.cpp @@ -336,7 +336,7 @@ void TC_Socket::parseAddr(const addr_type& addr, string& host, uint16_t &port) int iDomain; sockaddr_in6 *addr6; sockaddr_in *addr4; - if (addr.second == sizeof(sizeof(struct sockaddr_in6))) + if (addr.second == sizeof(struct sockaddr_in6)) { iDomain = AF_INET6; addr6 = (sockaddr_in6 *) addr.first.get(); diff --git a/util/src/tc_socket_async.cpp b/util/src/tc_socket_async.cpp index 1464fad4..371d20ca 100755 --- a/util/src/tc_socket_async.cpp +++ b/util/src/tc_socket_async.cpp @@ -61,7 +61,7 @@ TC_SocketAsync::~TC_SocketAsync() void TC_SocketAsync::resetTrans(const TC_Endpoint & ep) { _ep = ep; -#if TAF_SSL +#if TARS_SSL if (_ep.isSSL()) { _trans.reset(new TC_SSLTransceiver(_core->getEpoller(), _ep)); @@ -115,7 +115,7 @@ shared_ptr TC_SocketAsync::onCreateCallback(TC_Transceiver* trans) std::shared_ptr TC_SocketAsync::onOpensslCallback(TC_Transceiver* trans) { // LOG_CONSOLE_DEBUG << endl; -#if TAF_SSL +#if TARS_SSL if(trans->isSSL()) { if (!_ctx) { @@ -362,7 +362,7 @@ void TC_SocketAsync::reConnect() void TC_SocketAsync::setCtx(const std::string& cafile, const std::string& certfile, const std::string& keyfile, bool verifyClient, const string &ciphers) { -#if TAF_SSL +#if TARS_SSL _ctx = TC_OpenSSL::newCtx(cafile, certfile, keyfile, verifyClient, ciphers); #endif } diff --git a/util/src/tc_thread.cpp b/util/src/tc_thread.cpp index cbef24b6..8ac8d54a 100644 --- a/util/src/tc_thread.cpp +++ b/util/src/tc_thread.cpp @@ -249,14 +249,14 @@ bool TC_Thread::isAlive() const return _running; } -size_t TC_Thread::CURRENT_THREADID() +uint64_t TC_Thread::CURRENT_THREADID() { - static thread_local size_t threadId = 0; + static thread_local uint64_t threadId = 0; if(threadId == 0 ) { std::stringstream ss; ss << std::this_thread::get_id(); - threadId = strtol(ss.str().c_str(), NULL, 0); + threadId = std::strtoll(ss.str().c_str(), NULL, 0); } return threadId; } diff --git a/util/src/tc_timeprovider.cpp b/util/src/tc_timeprovider.cpp index e240efd8..eca0609e 100644 --- a/util/src/tc_timeprovider.cpp +++ b/util/src/tc_timeprovider.cpp @@ -90,16 +90,22 @@ uint64_t TC_TimeProvider::GetCycleCount() void TC_TimeProvider::getNow(timeval *tv) { #if TARGET_PLATFORM_IOS || TARGET_PLATFORM_LINUX - - int idx = _buf_idx; - *tv = _t[idx]; - if(fabs(_cpu_cycle - 0) < 0.0001 && _use_tsc) + if(GetCycleCount() != 0) { - addTimeOffset(*tv, idx); + int idx = _buf_idx; + *tv = _t[idx]; + if (fabs(_cpu_cycle - 0) < 0.0001 && _use_tsc) + { + addTimeOffset(*tv, idx); + } + else + { + TC_Common::gettimeofday(*tv); + } } else { - TC_Common::gettimeofday(*tv); + TC_Common::gettimeofday(*tv); } #else TC_Common::gettimeofday(*tv); diff --git a/util/src/tc_transceiver.cpp b/util/src/tc_transceiver.cpp index ac12680a..46bb4a54 100644 --- a/util/src/tc_transceiver.cpp +++ b/util/src/tc_transceiver.cpp @@ -166,6 +166,8 @@ void TC_Transceiver::initializeServer(const onclose_callback& onclose, _onCompleteNetworkCallback = onfinishAll; + parseConnectAddress(_ep); + #if TARS_SSL if (isSSL()) { @@ -243,7 +245,7 @@ shared_ptr TC_Transceiver::bindFd(int fd) _socketOpts[i].optlen); } - _clientAddr = TC_Socket::createSockAddr(_ep.getHost().c_str()); + _clientAddr = TC_Socket::createSockAddr(_ep); getpeername(_fd, _clientAddr.first.get(), &_clientAddr.second); @@ -289,7 +291,7 @@ void TC_Transceiver::checkConnect() THROW_ERROR(TC_Transceiver_Exception, CR_Connect, "connect " + _desc + " error:" + err); } - _clientAddr = TC_Socket::createSockAddr(_ep.getHost().c_str()); + _clientAddr = TC_Socket::createSockAddr(_ep); getpeername(_fd, _clientAddr.first.get(), &_clientAddr.second); @@ -306,26 +308,23 @@ void TC_Transceiver::checkConnect() } } -void TC_Transceiver::parseConnectAddress() +void TC_Transceiver::parseConnectAddress(const TC_Endpoint &ep) { #if !TARGET_PLATFORM_WINDOWS if (isUnixLocal()) { - TC_Socket::parseUnixLocalAddr(getConnectEndpoint().getHost().c_str(), - *(sockaddr_un*)_serverAddr.first.get()); + TC_Socket::parseUnixLocalAddr(ep.getHost().c_str(), *(sockaddr_un*)_serverAddr.first.get()); } else #endif { if (isConnectIPv6()) { - TC_Socket::parseAddrWithPort(getConnectEndpoint().getHost(), getConnectEndpoint().getPort(), - *(sockaddr_in6*)_serverAddr.first.get()); + TC_Socket::parseAddrWithPort(ep.getHost(), ep.getPort(), *(sockaddr_in6*)_serverAddr.first.get()); } else { - TC_Socket::parseAddrWithPort(getConnectEndpoint().getHost(), getConnectEndpoint().getPort(), - *(sockaddr_in*)_serverAddr.first.get()); + TC_Socket::parseAddrWithPort(ep.getHost(), ep.getPort(), *(sockaddr_in*)_serverAddr.first.get()); } } } @@ -367,7 +366,7 @@ void TC_Transceiver::connect() } //每次连接前都重新解析一下地址, 避免dns变了! - parseConnectAddress(); + parseConnectAddress(getConnectEndpoint()); } else { @@ -386,7 +385,7 @@ void TC_Transceiver::connect() } //每次连接前都重新解析一下地址, 避免dns变了! - parseConnectAddress(); + parseConnectAddress(getConnectEndpoint()); bool bConnected = doConnect(_fd, _serverAddr.first.get(), _serverAddr.second); if (bConnected) @@ -662,6 +661,8 @@ void TC_Transceiver::doRequest() auto data = _sendBuffer.getBufferPointer(); assert(data.first != NULL && data.second != 0); +// LOG_CONSOLE_DEBUG << "doRequest buff :" << string(data.first, (uint32_t)data.second) << endl; + int iRet = this->send(data.first, (uint32_t)data.second, 0); if (iRet <= 0) @@ -855,6 +856,12 @@ int TC_Transceiver::doProtocolAnalysis(TC_NetWorkBuffer* buff) throw TC_Transceiver_Exception(err); } + if(ret == TC_NetWorkBuffer::PACKET_ERR && _ep.isUdp()) + { + //udp包如果存在解析错误, 则将所有包都清掉, 避免一个包的污染 + _recvBuffer.clearBuffers(); + } + } while (ret == TC_NetWorkBuffer::PACKET_FULL); if (_onCompleteNetworkCallback) @@ -1315,7 +1322,7 @@ bool TC_UDPTransceiver::doResponse() { // _recvBuffer.clearBuffers(); - auto data = _recvBuffer.getOrCreateBuffer(_nRecvBufferSize, _nRecvBufferSize); + auto data = _recvBuffer.getOrCreateBuffer(_nRecvBufferSize, _nRecvBufferSize * 2); uint32_t left = (uint32_t)data->left(); @@ -1347,11 +1354,11 @@ int TC_UDPTransceiver::send(const void* buf, uint32_t len, uint32_t flag) if (_isServer) { iRet = ::sendto(_fd, (const char*)buf, len, flag, _lastAddr.first.get(), _lastAddr.second); - } + } else { iRet = ::sendto(_fd, (const char*)buf, len, flag, _serverAddr.first.get(), _serverAddr.second); - } + } if (iRet > 0) { @@ -1372,16 +1379,15 @@ int TC_UDPTransceiver::recv(void* buf, uint32_t len, uint32_t flag) { if (!isValid()) return -1; - if(!_clientAddr.first) { - _clientAddr = TC_Socket::createSockAddr(_ep.getHost().c_str()); - } + TC_Socket::addr_type clientAddr = TC_Socket::createSockAddr(_ep); + + _clientAddr = clientAddr; - int iRet = ::recvfrom(_fd, (char*)buf, len, flag, _clientAddr.first.get(), - &_clientAddr.second); //need check from_ip & port + int iRet = ::recvfrom(_fd, (char*)buf, len, flag, clientAddr.first.get(), &clientAddr.second); //need check from_ip & port if (!_isServer) { - //客户端才会关闭连接, 会重建socket, 服务端不会 + //客户端才会关闭连接, 会重建socket, 服务端不会 if (iRet < 0 && !TC_Socket::isPending()) { THROW_ERROR(TC_Transceiver_Exception, CR_RECV,