interface_analysis.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  7. * in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * https://opensource.org/licenses/BSD-3-Clause
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. */
  16. #include "interface_analysis.h"
  17. #include <vector>
  18. InterfaceAnalysis::InterfaceAnalysis() {
  19. }
  20. void InterfaceAnalysis::analysis(const vector<InterfacePtr>& interfacePtrs) {
  21. for (size_t index = 0; index < interfacePtrs.size(); ++index) {
  22. analysis(interfacePtrs[index]);
  23. }
  24. }
  25. void InterfaceAnalysis::analysis(const InterfacePtr& interfacePtr) {
  26. const vector<OperationPtr>& operations = interfacePtr->getAllOperationPtr();
  27. for (size_t operationIndex = 0; operationIndex < operations.size(); ++operationIndex) {
  28. const OperationPtr& operation = operations[operationIndex];
  29. analysis(operation->getReturnPtr()->getTypePtr());
  30. const vector<ParamDeclPtr>& paramDecls = operation->getAllParamDeclPtr();
  31. for (size_t paramIndex = 0; paramIndex < paramDecls.size(); paramIndex++) {
  32. const ParamDeclPtr& paramDeclPtr = paramDecls[paramIndex];
  33. analysis(paramDeclPtr->getTypeIdPtr()->getTypePtr());
  34. }
  35. }
  36. }
  37. void InterfaceAnalysis::analysis(const StructPtr& structPtr) {
  38. const vector<TypeIdPtr>& allMembersPtr = structPtr->getAllMemberPtr();
  39. for (size_t index = 0; index < allMembersPtr.size(); ++index) {
  40. analysis(allMembersPtr[index]->getTypePtr());
  41. }
  42. }
  43. void InterfaceAnalysis::analysis(const TypePtr& typePtr) {
  44. VectorPtr vPtr = VectorPtr::dynamicCast(typePtr);
  45. if (vPtr) {
  46. analysis(vPtr->getTypePtr());
  47. return ;
  48. }
  49. MapPtr mPtr = MapPtr::dynamicCast(typePtr);
  50. if (mPtr) {
  51. analysis(mPtr->getLeftTypePtr());
  52. analysis(mPtr->getRightTypePtr());
  53. return ;
  54. }
  55. StructPtr sPtr = StructPtr::dynamicCast(typePtr);
  56. if (sPtr) {
  57. // 说明已经分析过,并且找到了
  58. if (mAllStructs.find(sPtr->getSid()) != mAllStructs.end()) {
  59. return ;
  60. }
  61. mAllStructs.insert(std::pair<std::string, StructPtr>(sPtr->getSid(), sPtr));
  62. analysis(sPtr);
  63. }
  64. EnumPtr ePtr = EnumPtr::dynamicCast(typePtr);
  65. if (ePtr) {
  66. if (mAllEnums.find(ePtr->getSid()) != mAllEnums.end()) {
  67. return ;
  68. }
  69. mAllEnums.insert(std::pair<std::string, EnumPtr>(ePtr->getSid(), ePtr));
  70. }
  71. }
  72. const std::map<std::string, StructPtr>& InterfaceAnalysis::getAllStructs() const {
  73. return mAllStructs;
  74. }
  75. const std::map<std::string, EnumPtr>& InterfaceAnalysis::getAllEnums() const {
  76. return mAllEnums;
  77. }
  78. const std::map<std::string, ConstPtr>& InterfaceAnalysis::getAllConsts() const {
  79. return mAllConsts;
  80. }