You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CdtCppFileParser.java 3.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. MIT License
  3. Copyright (c) 2018-2019 Gang ZHANG
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in all
  11. copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  18. SOFTWARE.
  19. */
  20. package depends.extractor.cpp.cdt;
  21. import depends.entity.repo.EntityRepo;
  22. import depends.extractor.cpp.CppFileParser;
  23. import depends.extractor.cpp.MacroRepo;
  24. import depends.relations.IBindingResolver;
  25. import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
  26. import java.io.IOException;
  27. import java.util.HashMap;
  28. import java.util.Map;
  29. public class CdtCppFileParser extends CppFileParser {
  30. private PreprocessorHandler preprocessorHandler ;
  31. private IBindingResolver bindingResolver;
  32. private MacroRepo macroRepo;
  33. public CdtCppFileParser(EntityRepo entityRepo, PreprocessorHandler preprocessorHandler, IBindingResolver bindingResolver, MacroRepo macroRepo) {
  34. super(entityRepo);
  35. this.preprocessorHandler = preprocessorHandler;
  36. this.bindingResolver = bindingResolver;
  37. this.macroRepo= macroRepo;
  38. }
  39. @Override
  40. protected void parseFile(String fileFullPath) throws IOException {
  41. Map<String, String> macroMap = new HashMap<>(macroRepo.getDefaultMap());
  42. parse(fileFullPath,macroMap);
  43. }
  44. /**
  45. *
  46. * @param isInScope whether the parse is invoked by project file or an 'indirect' included file
  47. * @return
  48. */
  49. public void parse(String fileFullPath,Map<String, String> macroMap) throws IOException {
  50. CppVisitor bridge = new CppVisitor(fileFullPath, entityRepo, preprocessorHandler, bindingResolver);
  51. IASTTranslationUnit tu = (new CDTParser(preprocessorHandler.getIncludePaths())).parse(fileFullPath,macroMap);
  52. boolean containsIncludes = false;
  53. for (String incl:preprocessorHandler.getDirectIncludedFiles(tu.getAllPreprocessorStatements(),fileFullPath)) {
  54. CdtCppFileParser importedParser = new CdtCppFileParser(entityRepo, preprocessorHandler, bindingResolver,macroRepo);
  55. importedParser.parse(incl);
  56. Map<String, String> macros = macroRepo.get(incl);
  57. if (macros!=null)
  58. macroMap.putAll(macros);
  59. containsIncludes = true;
  60. }
  61. if (containsIncludes) {
  62. tu = (new CDTParser(preprocessorHandler.getIncludePaths())).parse(fileFullPath,macroMap);
  63. }
  64. macroRepo.putMacros(fileFullPath,macroMap,tu.getMacroDefinitions());
  65. tu.accept(bridge);
  66. return;
  67. }
  68. @Override
  69. protected boolean isPhase2Files(String fileFullPath) {
  70. if (fileFullPath.endsWith(".h") || fileFullPath.endsWith(".hh") || fileFullPath.endsWith(".hpp")
  71. || fileFullPath.endsWith(".hxx"))
  72. return true;
  73. return false;
  74. }
  75. }

GeekAI 是基于 AI 大语言模型 API 实现的 AI 助手全套开源解决方案,自带运营管理后台,开箱即用。集成了 OpenAI, Azure, ChatGLM,讯飞星火,文心一言等多个平台的大语言模型。采用 Go + Vue3 + element-plus 实现。

Contributors (2)