summaryrefslogtreecommitdiff
path: root/autoload
diff options
context:
space:
mode:
authorLouis Xu <wickedbinary@gmail.com>2019-01-22 10:45:17 +0800
committerLouis Xu <wickedbinary@gmail.com>2019-01-24 09:44:52 +0800
commit8037f472effbc01f6fe3ec0f84495a8ca100e7b5 (patch)
treea9a7a6967292b7a32c344365078eec01b88e74e4 /autoload
parentf12d312aa4aa49c4698056933030cd5adb60b489 (diff)
downloadale-8037f472effbc01f6fe3ec0f84495a8ca100e7b5.zip
Parse more C/C++ compiler options
Diffstat (limited to 'autoload')
-rw-r--r--autoload/ale/c.vim68
1 files changed, 30 insertions, 38 deletions
diff --git a/autoload/ale/c.vim b/autoload/ale/c.vim
index 6ad5d328..5e7aa92a 100644
--- a/autoload/ale/c.vim
+++ b/autoload/ale/c.vim
@@ -79,51 +79,43 @@ function! ale#c#AreSpecialCharsBalanced(option) abort
endfunction
function! ale#c#ParseCFlags(path_prefix, cflag_line) abort
- let l:cflags_list = []
- let l:previous_options = ''
-
- let l:split_lines = split(a:cflag_line, ' ')
+ let l:split_lines = split(a:cflag_line)
let l:option_index = 0
while l:option_index < len(l:split_lines)
- let l:option = l:previous_options . l:split_lines[l:option_index]
- let l:option_index = l:option_index + 1
-
- " Check if cflag contained an unmatched special character and should not have been splitted
- if ale#c#AreSpecialCharsBalanced(l:option) == 0 && l:option_index < len(l:split_lines)
- let l:previous_options = l:option . ' '
- continue
- endif
-
- " Check if there was spaces after -D/-I and the flag should not have been splitted
- if l:option is# '-D' || l:option is# '-I'
- let l:previous_options = l:option
- continue
- endif
-
- let l:previous_options = ''
-
-
- " Fix relative paths if needed
- if stridx(l:option, '-I') >= 0 &&
- \ stridx(l:option, '-I' . s:sep) < 0
- let l:rel_path = join(split(l:option, '\zs')[2:], '')
- let l:rel_path = substitute(l:rel_path, '"', '', 'g')
- let l:rel_path = substitute(l:rel_path, '''', '', 'g')
- let l:option = ale#Escape('-I' . a:path_prefix .
- \ s:sep . l:rel_path)
- endif
-
- " Parse the cflag
- if stridx(l:option, '-I') >= 0 ||
- \ stridx(l:option, '-D') >= 0
- if index(l:cflags_list, l:option) < 0
- call add(l:cflags_list, l:option)
+ let l:next_option_index = l:option_index + 1
+
+ " Join space-separated option
+ while l:next_option_index < len(l:split_lines) &&
+ \ stridx(l:split_lines[l:next_option_index], '-') != 0
+ let l:next_option_index += 1
+ endwhile
+
+ let l:option = join(l:split_lines[l:option_index : l:next_option_index-1], ' ')
+ call remove(l:split_lines, l:option_index, l:next_option_index-1)
+ call insert(l:split_lines, l:option, l:option_index)
+
+ " Ignore invalid or conflicting options
+ if stridx(l:option, '-') != 0 ||
+ \ stridx(l:option, '-o') == 0 ||
+ \ stridx(l:option, '-c') == 0
+ call remove(l:split_lines, l:option_index)
+ let l:option_index = l:option_index - 1
+ " Fix relative path
+ elseif stridx(l:option, '-I') == 0
+ if !(stridx(l:option, ':') == 2+1 || stridx(l:option, '/') == 2+0)
+ let l:option = '-I' . a:path_prefix . s:sep . l:option[2:]
+ call remove(l:split_lines, l:option_index)
+ call insert(l:split_lines, l:option, l:option_index)
endif
endif
+
+ let l:option_index = l:option_index + 1
endwhile
- return join(l:cflags_list, ' ')
+ call uniq(l:split_lines)
+
+ return join(l:split_lines, ' ')
endfunction
function! ale#c#ParseCFlagsFromMakeOutput(buffer, make_output) abort