Cycles OpenCL: use #line directives for better error messages.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Sat, 30 Jul 2016 14:54:48 +0000 (16:54 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Sat, 30 Jul 2016 16:25:52 +0000 (18:25 +0200)
intern/cycles/util/util_path.cpp
intern/cycles/util/util_string.cpp
intern/cycles/util/util_string.h

index 0c848beaafd1c049014c024e8cc69a33da3e9504..800dfa273bdcf0eff62ff60e10e02c04614160cd 100644 (file)
@@ -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());
                                        }
                                }
                        }
index c1c5a6b084b2317e3a58b2175205492372ee559a..5594aa8edb657d0e12f2b0d1035cd2522b2caafe 100644 (file)
@@ -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);
                        }
index d3b5248c3808106ed5656bb7c7bb28a1006bed93..7aeed96f00bb568fc4addaf2158686a1a4422062 100644 (file)
@@ -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);