1 // Copyright 2015 The Shaderc Authors. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef LIBSHADERC_UTIL_SRC_MESSAGE_H_ 16 #define LIBSHADERC_UTIL_SRC_MESSAGE_H_ 17 18 #include "libshaderc_util/string_piece.h" 19 20 namespace shaderc_util { 21 22 // TODO(antiagainst): document the differences of the following message types. 23 enum class MessageType { 24 Warning, 25 Error, 26 ErrorSummary, 27 WarningSummary, 28 GlobalWarning, 29 GlobalError, 30 Unknown, 31 Ignored 32 }; 33 34 // Given a glslang warning/error message, processes it in the following way and 35 // returns its message type. 36 // 37 // * Places the source name into the source_name parameter, if found. 38 // Otherwise, clears the source_name parameter. 39 // * Places the line number into the line_number parameter, if found. 40 // Otherwise, clears the line_number parameter. 41 // * Places the rest of the message (the text past warning/error prefix, source 42 // name, and line number) into the rest parameter. 43 // 44 // If warnings_as_errors is set to true, then all warnings will be treated as 45 // errors. 46 // If suppress_warnings is set to true, then no warnings will be emitted. This 47 // takes precedence over warnings_as_errors. 48 // 49 // Examples: 50 // "ERROR: 0:2: Message" 51 // source_name="0", line_number="2", rest="Message" 52 // "Warning, Message" 53 // source_name="", line_number="", rest="Message" 54 // "ERROR: 2 errors found." 55 // source_name="2", line_number="", rest="errors found". 56 MessageType ParseGlslangOutput(const shaderc_util::string_piece& message, 57 bool warnings_as_errors, bool suppress_warnings, 58 shaderc_util::string_piece* source_name, 59 shaderc_util::string_piece* line_number, 60 shaderc_util::string_piece* rest); 61 62 // Filters error_messages received from glslang, and outputs, to error_stream, 63 // any that are not ignored in a clang like format. If the warnings_as_errors 64 // boolean is set, then all warnings will be treated as errors. If the 65 // suppress_warnings boolean is set then any warning messages are ignored. This 66 // takes precedence over warnings_as_errors. Increments total_warnings and 67 // total_errors based on the message types. 68 // Returns true if no new errors were found when parsing the messages. 69 // "<command line>" will substitute "-1" appearing at the string name/number 70 // segment. 71 bool PrintFilteredErrors(const shaderc_util::string_piece& file_name, 72 std::ostream* error_stream, bool warnings_as_errors, 73 bool suppress_warnings, const char* error_list, 74 size_t* total_warnings, size_t* total_errors); 75 76 // Outputs, to error_stream, the number of warnings and errors if there are 77 // any. 78 void OutputMessages(std::ostream* error_stream, size_t total_warnings, 79 size_t total_errors); 80 81 } // namespace glslc 82 83 #endif // LIBSHADERC_UTIL_SRC_MESSAGE_H_ 84