diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-07-30 17:54:48 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2016-07-30 19:25:52 +0300 |
commit | 1e2efbc908cfa97d433cb23998bacc39d66d9c93 (patch) | |
tree | 8d4b46752d9486fe10049e5df4d12a5658c73654 /intern/cycles/util | |
parent | 6dc72b3ce6943bb444a6d6a4029cc8ce5b5bdf45 (diff) |
Cycles OpenCL: use #line directives for better error messages.
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/util_path.cpp | 9 | ||||
-rw-r--r-- | intern/cycles/util/util_string.cpp | 9 | ||||
-rw-r--r-- | intern/cycles/util/util_string.h | 5 |
3 files changed, 18 insertions, 5 deletions
diff --git a/intern/cycles/util/util_path.cpp b/intern/cycles/util/util_path.cpp index 0c848beaafd..800dfa273bd 100644 --- a/intern/cycles/util/util_path.cpp +++ b/intern/cycles/util/util_path.cpp @@ -737,7 +737,7 @@ string path_source_replace_includes(const string& source, const string& path) string result = ""; vector<string> lines; - string_split(lines, source, "\n"); + string_split(lines, source, "\n", false); for(size_t i = 0; i < lines.size(); ++i) { string line = lines[i]; @@ -760,6 +760,13 @@ string path_source_replace_includes(const string& source, const string& path) text, path_dirname(filepath)); text = path_source_replace_includes(text, path); line = token.replace(0, n_end + 1, "\n" + text + "\n"); + + /* Line directives for better error messages. */ + line = string_printf("#line %d \"%s\"\n", + (int)0, filepath.c_str()) + + line + + string_printf("\n#line %d \"%s\"", + (int)i, path.c_str()); } } } diff --git a/intern/cycles/util/util_string.cpp b/intern/cycles/util/util_string.cpp index c1c5a6b084b..5594aa8edb6 100644 --- a/intern/cycles/util/util_string.cpp +++ b/intern/cycles/util/util_string.cpp @@ -74,7 +74,10 @@ bool string_iequals(const string& a, const string& b) return false; } -void string_split(vector<string>& tokens, const string& str, const string& separators) +void string_split(vector<string>& tokens, + const string& str, + const string& separators, + bool skip_empty_tokens) { size_t token_start = 0, token_length = 0; for(size_t i = 0; i < str.size(); ++i) { @@ -87,9 +90,9 @@ void string_split(vector<string>& tokens, const string& str, const string& separ } else { /* Current character is a separator, - * append current token to the list (if token is not empty). + * append current token to the list. */ - if(token_length > 0) { + if(!skip_empty_tokens || token_length > 0) { string token = str.substr(token_start, token_length); tokens.push_back(token); } diff --git a/intern/cycles/util/util_string.h b/intern/cycles/util/util_string.h index d3b5248c380..7aeed96f00b 100644 --- a/intern/cycles/util/util_string.h +++ b/intern/cycles/util/util_string.h @@ -39,7 +39,10 @@ using std::istringstream; string string_printf(const char *format, ...) PRINTF_ATTRIBUTE; bool string_iequals(const string& a, const string& b); -void string_split(vector<string>& tokens, const string& str, const string& separators = "\t "); +void string_split(vector<string>& tokens, + const string& str, + const string& separators = "\t ", + bool skip_empty_tokens = true); void string_replace(string& haystack, const string& needle, const string& other); bool string_startswith(const string& s, const char *start); bool string_endswith(const string& s, const char *end); |