diff --git a/include/cppast/diagnostic.hpp b/include/cppast/diagnostic.hpp index a811610..ba7d547 100644 --- a/include/cppast/diagnostic.hpp +++ b/include/cppast/diagnostic.hpp @@ -17,30 +17,33 @@ namespace cppast { type_safe::optional entity; type_safe::optional file; - type_safe::optional line; + type_safe::optional line, column; /// \returns A source location where all information is available. - static source_location make(std::string entity, std::string file, unsigned line) + static source_location make(std::string entity, std::string file, unsigned line, + unsigned column) { - return {std::move(entity), std::move(file), line}; + return {std::move(entity), std::move(file), line, column}; } - /// \returns A source location where only file and line information is available. - static source_location make_file(std::string file, unsigned line) + /// \returns A source location where only file information is available. + static source_location make_file(std::string file, + type_safe::optional line = type_safe::nullopt, + type_safe::optional column = type_safe::nullopt) { - return {type_safe::nullopt, std::move(file), line}; - } - - /// \returns A source location where only the file is available. - static source_location make_file(std::string file) - { - return {type_safe::nullopt, std::move(file), type_safe::nullopt}; + return {type_safe::nullopt, std::move(file), line, column}; } /// \returns A source location where only the entity name is available. static source_location make_entity(std::string entity) { - return {std::move(entity), type_safe::nullopt, type_safe::nullopt}; + return {std::move(entity), type_safe::nullopt, type_safe::nullopt, type_safe::nullopt}; + } + + /// \returns A source location where no information is avilable. + static source_location make_unknown() + { + return {type_safe::nullopt, type_safe::nullopt, type_safe::nullopt, type_safe::nullopt}; } /// \returns A possible string representation of the source location. @@ -51,8 +54,17 @@ namespace cppast if (file) { result += file.value() + ":"; + if (line) - result += std::to_string(line.value()) + ":"; + { + result += std::to_string(line.value()); + + if (column) + result += "," + std::to_string(column.value()); + + result += ":"; + } + if (entity) result += " (" + entity.value() + "):"; } diff --git a/src/libclang/preprocessor.cpp b/src/libclang/preprocessor.cpp index 0630979..ae75e7b 100644 --- a/src/libclang/preprocessor.cpp +++ b/src/libclang/preprocessor.cpp @@ -102,7 +102,7 @@ namespace DEBUG_ASSERT(*ptr == ':', detail::assert_handler{}); ++ptr; - return {type_safe::nullopt, std::move(filename), std::move(line)}; + return {type_safe::nullopt, std::move(filename), std::move(line), type_safe::nullopt}; } severity parse_severity(const char*& ptr)