|
| 1 | +#ifndef NOMIC_CORE_CLANG_PARSER_H |
| 2 | +#define NOMIC_CORE_CLANG_PARSER_H |
| 3 | + |
| 4 | +#include "nomic/core/interfaces.h" |
| 5 | +#include <string> |
| 6 | +#include <vector> |
| 7 | +#include <memory> |
| 8 | + |
| 9 | +namespace nomic { |
| 10 | +namespace core { |
| 11 | + |
| 12 | +/** |
| 13 | + * @brief Clang-based C source code parser |
| 14 | + * |
| 15 | + * This class integrates with Clang/LLVM to parse C source files and |
| 16 | + * convert them into Nomic's AST representation. |
| 17 | + */ |
| 18 | +class ClangParser { |
| 19 | +public: |
| 20 | + /** |
| 21 | + * @brief Parse options for Clang parser |
| 22 | + */ |
| 23 | + struct ParseOptions { |
| 24 | + std::vector<std::string> includePaths; // -I paths |
| 25 | + std::vector<std::string> defines; // -D defines |
| 26 | + std::vector<std::string> compilerFlags; // Additional flags |
| 27 | + std::string compilationDatabase; // Path to compile_commands.json |
| 28 | + bool parsePreprocessor = true; // Include preprocessor info |
| 29 | + bool parseComments = true; // Include comments |
| 30 | + bool verbose = false; // Verbose output |
| 31 | + }; |
| 32 | + |
| 33 | + /** |
| 34 | + * @brief Parse result containing AST and semantic model |
| 35 | + */ |
| 36 | + struct ParseResult { |
| 37 | + ASTNodePtr ast; // Root AST node |
| 38 | + SemanticModelPtr semanticModel; // Semantic model |
| 39 | + std::vector<std::string> errors; // Parse errors |
| 40 | + std::vector<std::string> warnings; // Parse warnings |
| 41 | + bool success = false; // Overall success |
| 42 | + }; |
| 43 | + |
| 44 | + ClangParser(); |
| 45 | + ~ClangParser(); |
| 46 | + |
| 47 | + /** |
| 48 | + * @brief Parse a single C source file |
| 49 | + * @param filePath Path to C source file |
| 50 | + * @param options Parse options |
| 51 | + * @return Parse result with AST and semantic model |
| 52 | + */ |
| 53 | + ParseResult parseFile(const std::string& filePath, const ParseOptions& options = ParseOptions()); |
| 54 | + |
| 55 | + /** |
| 56 | + * @brief Parse multiple C source files |
| 57 | + * @param filePaths Vector of file paths |
| 58 | + * @param options Parse options |
| 59 | + * @return Parse result with combined AST |
| 60 | + */ |
| 61 | + ParseResult parseFiles(const std::vector<std::string>& filePaths, const ParseOptions& options = ParseOptions()); |
| 62 | + |
| 63 | + /** |
| 64 | + * @brief Parse C source code from string |
| 65 | + * @param source Source code string |
| 66 | + * @param filename Virtual filename for diagnostics |
| 67 | + * @param options Parse options |
| 68 | + * @return Parse result |
| 69 | + */ |
| 70 | + ParseResult parseString(const std::string& source, const std::string& filename = "input.c", const ParseOptions& options = ParseOptions()); |
| 71 | + |
| 72 | +private: |
| 73 | + class Impl; |
| 74 | + std::unique_ptr<Impl> pImpl; |
| 75 | +}; |
| 76 | + |
| 77 | +} // namespace core |
| 78 | +} // namespace nomic |
| 79 | + |
| 80 | +#endif // NOMIC_CORE_CLANG_PARSER_H |
0 commit comments