| 138 | } |
| 139 | |
| 140 | int MetaParser::parse(void) |
| 141 | { |
| 142 | bool parse_include_ = parseProject(); |
| 143 | if (!parse_include_) |
| 144 | { |
| 145 | std::cerr << "Parsing project file error! " << std::endl; |
| 146 | return -1; |
| 147 | } |
| 148 | |
| 149 | std::cerr << "Parsing the whole project..." << std::endl; |
| 150 | int is_show_errors = m_is_show_errors ? 1 : 0; |
| 151 | m_index = clang_createIndex(true, is_show_errors); |
| 152 | std::string pre_include = "-I"; |
| 153 | std::string sys_include_temp; |
| 154 | if (!(m_sys_include == "*")) |
| 155 | { |
| 156 | sys_include_temp = pre_include + m_sys_include; |
| 157 | arguments.emplace_back(sys_include_temp.c_str()); |
| 158 | } |
| 159 | |
| 160 | auto paths = m_work_paths; |
| 161 | for (int index = 0; index < paths.size(); ++index) |
| 162 | { |
| 163 | paths[index] = pre_include + paths[index]; |
| 164 | |
| 165 | arguments.emplace_back(paths[index].c_str()); |
| 166 | } |
| 167 | |
| 168 | fs::path input_path(m_source_include_file_name); |
| 169 | if (!fs::exists(input_path)) |
| 170 | { |
| 171 | std::cerr << input_path << " is not exist" << std::endl; |
| 172 | return -2; |
| 173 | } |
| 174 | |
| 175 | m_translation_unit = clang_createTranslationUnitFromSourceFile( |
| 176 | m_index, m_source_include_file_name.c_str(), static_cast<int>(arguments.size()), arguments.data(), 0, nullptr); |
| 177 | auto cursor = clang_getTranslationUnitCursor(m_translation_unit); |
| 178 | |
| 179 | Namespace temp_namespace; |
| 180 | |
| 181 | buildClassAST(cursor, temp_namespace); |
| 182 | |
| 183 | temp_namespace.clear(); |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | void MetaParser::generateFiles(void) |
| 189 | { |