Merge lp:~monkey-libre/valide/update-afrodite into lp:valide
- update-afrodite
- Merge into trunk
Proposed by
Monkey
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 595 | ||||
Proposed branch: | lp:~monkey-libre/valide/update-afrodite | ||||
Merge into: | lp:valide | ||||
Diff against target: |
2247 lines (+774/-610) 13 files modified
plugins/completion/afrodite-provider/afrodite-provider.vala (+27/-36) plugins/completion/afrodite-provider/afrodite/Makefile.am (+1/-1) plugins/completion/afrodite-provider/afrodite/afroditetest.vala (+122/-115) plugins/completion/afrodite-provider/afrodite/ast.vala (+9/-38) plugins/completion/afrodite-provider/afrodite/astdumper.vala (+1/-1) plugins/completion/afrodite-provider/afrodite/astmerger.vala (+299/-156) plugins/completion/afrodite-provider/afrodite/completionengine.vala (+202/-199) plugins/completion/afrodite-provider/afrodite/parser.vala (+10/-11) plugins/completion/afrodite-provider/afrodite/parseresult.vala (+5/-0) plugins/completion/afrodite-provider/afrodite/sourcefile.vala (+2/-25) plugins/completion/afrodite-provider/afrodite/sourcereference.vala (+6/-6) plugins/completion/afrodite-provider/afrodite/symbol.vala (+27/-14) plugins/completion/afrodite-provider/afrodite/symbolresolver.vala (+63/-8) |
||||
To merge this branch: | bzr merge lp:~monkey-libre/valide/update-afrodite | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Val(a)IDE Team | Pending | ||
Review via email: mp+52905@code.launchpad.net |
Commit message
Description of the change
Update Afrodite from vtg-0.11.1
Changes in the api:
Removed the try_acquire_ast / release_ast
Works very fast and without any problem. More info attached in the bug.
Thanks in advance.
To post a comment you must log in.
Revision history for this message
Monkey (monkey-libre) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'plugins/completion/afrodite-provider/afrodite-provider.vala' | |||
2 | --- plugins/completion/afrodite-provider/afrodite-provider.vala 2011-02-20 14:12:17 +0000 | |||
3 | +++ plugins/completion/afrodite-provider/afrodite-provider.vala 2011-03-10 19:26:24 +0000 | |||
4 | @@ -737,40 +737,35 @@ | |||
5 | 737 | first_part = word; // "this"; //HACK: this won't work for static methods | 737 | first_part = word; // "this"; //HACK: this won't work for static methods |
6 | 738 | } | 738 | } |
7 | 739 | 739 | ||
9 | 740 | Afrodite.Ast ast; | 740 | Afrodite.Ast ast = completion.ast; |
10 | 741 | Afrodite.Symbol? symbol = null; | 741 | Afrodite.Symbol? symbol = null; |
17 | 742 | 742 | Afrodite.QueryResult? result = null; | |
18 | 743 | if (this.completion.try_acquire_ast (out ast, retry_count)) | 743 | Afrodite.QueryOptions options = this.get_options_for_line (text, is_assignment, is_creation); |
19 | 744 | { | 744 | |
20 | 745 | Afrodite.QueryResult? result = null; | 745 | if (word == symbol_name) |
21 | 746 | Afrodite.QueryOptions options = this.get_options_for_line (text, is_assignment, is_creation); | 746 | { |
22 | 747 | 747 | result = this.get_symbol_for_name (options, ast, first_part, null, line, col); | |
23 | 748 | } | ||
24 | 749 | else | ||
25 | 750 | { | ||
26 | 751 | result = this.get_symbol_type_for_name (options, ast, first_part, null, line, col); | ||
27 | 752 | } | ||
28 | 753 | |||
29 | 754 | if (result != null && !result.is_empty) | ||
30 | 755 | { | ||
31 | 756 | var first = result.children.get (0); | ||
32 | 748 | if (word == symbol_name) | 757 | if (word == symbol_name) |
33 | 749 | { | 758 | { |
35 | 750 | result = this.get_symbol_for_name (options, ast, first_part, null, line, col); | 759 | symbol = first.symbol; |
36 | 751 | } | 760 | } |
37 | 752 | else | 761 | else |
38 | 753 | { | 762 | { |
59 | 754 | result = this.get_symbol_type_for_name (options, ast, first_part, null, line, col); | 763 | symbol = this.get_symbol_for_name_in_children (symbol_name, first.symbol); |
60 | 755 | } | 764 | if (symbol == null) |
61 | 756 | 765 | { | |
62 | 757 | if (result != null && !result.is_empty) | 766 | symbol =this.get_symbol_for_name_in_base_types (symbol_name, first.symbol); |
63 | 758 | { | 767 | } |
64 | 759 | var first = result.children.get (0); | 768 | } |
45 | 760 | if (word == symbol_name) | ||
46 | 761 | { | ||
47 | 762 | symbol = first.symbol; | ||
48 | 763 | } | ||
49 | 764 | else | ||
50 | 765 | { | ||
51 | 766 | symbol = this.get_symbol_for_name_in_children (symbol_name, first.symbol); | ||
52 | 767 | if (symbol == null) | ||
53 | 768 | { | ||
54 | 769 | symbol =this.get_symbol_for_name_in_base_types (symbol_name, first.symbol); | ||
55 | 770 | } | ||
56 | 771 | } | ||
57 | 772 | } | ||
58 | 773 | this.completion.release_ast (ast); | ||
65 | 774 | } | 769 | } |
66 | 775 | return symbol; | 770 | return symbol; |
67 | 776 | } | 771 | } |
68 | @@ -857,10 +852,9 @@ | |||
69 | 857 | 852 | ||
70 | 858 | Vtg.ParserUtils.parse_line (text, out word, out is_assignment, out is_creation, out is_declaration); | 853 | Vtg.ParserUtils.parse_line (text, out word, out is_assignment, out is_creation, out is_declaration); |
71 | 859 | 854 | ||
73 | 860 | Afrodite.Ast ast = null; | 855 | Afrodite.Ast ast = completion.ast; |
74 | 861 | Vtg.Utils.trace ("completing word: '%s'", word); | 856 | Vtg.Utils.trace ("completing word: '%s'", word); |
77 | 862 | if (!Vtg.StringUtils.is_null_or_empty (word) | 857 | if (!Vtg.StringUtils.is_null_or_empty (word)) |
76 | 863 | && this.completion.try_acquire_ast (out ast)) | ||
78 | 864 | { | 858 | { |
79 | 865 | Afrodite.QueryOptions options = this.get_options_for_line (text, is_assignment, is_creation); | 859 | Afrodite.QueryOptions options = this.get_options_for_line (text, is_assignment, is_creation); |
80 | 866 | Afrodite.QueryResult result = null; | 860 | Afrodite.QueryResult result = null; |
81 | @@ -878,7 +872,6 @@ | |||
82 | 878 | } | 872 | } |
83 | 879 | result = this.get_symbol_type_for_name (options, ast, word, text, line, col); | 873 | result = this.get_symbol_type_for_name (options, ast, word, text, line, col); |
84 | 880 | this.transform_result (options, result); | 874 | this.transform_result (options, result); |
85 | 881 | this.completion.release_ast (ast); | ||
86 | 882 | } | 875 | } |
87 | 883 | else | 876 | else |
88 | 884 | { | 877 | { |
89 | @@ -895,12 +888,11 @@ | |||
90 | 895 | 888 | ||
91 | 896 | private void lookup_visible_symbols_in_scope (string word, Afrodite.CompareMode mode) | 889 | private void lookup_visible_symbols_in_scope (string word, Afrodite.CompareMode mode) |
92 | 897 | { | 890 | { |
94 | 898 | Afrodite.Ast ast = null; | 891 | Afrodite.Ast ast = completion.ast; |
95 | 899 | Vtg.Utils.trace ("lookup_all_symbols_in_scope: mode: %s word:'%s' ", | 892 | Vtg.Utils.trace ("lookup_all_symbols_in_scope: mode: %s word:'%s' ", |
96 | 900 | mode == Afrodite.CompareMode.EXACT ? "exact" : "start-with", | 893 | mode == Afrodite.CompareMode.EXACT ? "exact" : "start-with", |
97 | 901 | word); | 894 | word); |
100 | 902 | if (!Vtg.StringUtils.is_null_or_empty (word) | 895 | if (!Vtg.StringUtils.is_null_or_empty (word)) |
99 | 903 | && this.completion.try_acquire_ast (out ast, 0)) | ||
101 | 904 | { | 896 | { |
102 | 905 | Vala.List<Afrodite.Symbol> results = new Vala.ArrayList<Afrodite.Symbol> (); | 897 | Vala.List<Afrodite.Symbol> results = new Vala.ArrayList<Afrodite.Symbol> (); |
103 | 906 | 898 | ||
104 | @@ -929,7 +921,6 @@ | |||
105 | 929 | this.proposals = new List<Gtk.SourceCompletionItem> (); | 921 | this.proposals = new List<Gtk.SourceCompletionItem> (); |
106 | 930 | append_symbols (null, results); | 922 | append_symbols (null, results); |
107 | 931 | } | 923 | } |
108 | 932 | this.completion.release_ast (ast); | ||
109 | 933 | } | 924 | } |
110 | 934 | else | 925 | else |
111 | 935 | { | 926 | { |
112 | 936 | 927 | ||
113 | === modified file 'plugins/completion/afrodite-provider/afrodite/Makefile.am' | |||
114 | --- plugins/completion/afrodite-provider/afrodite/Makefile.am 2010-10-14 16:01:50 +0000 | |||
115 | +++ plugins/completion/afrodite-provider/afrodite/Makefile.am 2011-03-10 19:26:24 +0000 | |||
116 | @@ -61,7 +61,7 @@ | |||
117 | 61 | touch $@ | 61 | touch $@ |
118 | 62 | 62 | ||
119 | 63 | libafrodite_la_LDFLAGS = \ | 63 | libafrodite_la_LDFLAGS = \ |
121 | 64 | -version-info 0:1:0 \ | 64 | -version-info 1:0:0 \ |
122 | 65 | $(NULL) | 65 | $(NULL) |
123 | 66 | 66 | ||
124 | 67 | libafrodite_la_LIBADD = \ | 67 | libafrodite_la_LIBADD = \ |
125 | 68 | 68 | ||
126 | === modified file 'plugins/completion/afrodite-provider/afrodite/afroditetest.vala' | |||
127 | --- plugins/completion/afrodite-provider/afrodite/afroditetest.vala 2010-10-14 16:01:50 +0000 | |||
128 | +++ plugins/completion/afrodite-provider/afrodite/afroditetest.vala 2011-03-10 19:26:24 +0000 | |||
129 | @@ -47,10 +47,11 @@ | |||
130 | 47 | }; | 47 | }; |
131 | 48 | 48 | ||
132 | 49 | public class AfroditeTest.Application : Object { | 49 | public class AfroditeTest.Application : Object { |
133 | 50 | |||
134 | 51 | private MainLoop _loop; | ||
135 | 52 | private Afrodite.CompletionEngine _engine; | ||
136 | 53 | |||
137 | 50 | public int run (string[] args) { | 54 | public int run (string[] args) { |
138 | 51 | int i = 0; | ||
139 | 52 | int result = 0; | ||
140 | 53 | |||
141 | 54 | // parse options | 55 | // parse options |
142 | 55 | var opt_context = new OptionContext ("- Afrodite Test"); | 56 | var opt_context = new OptionContext ("- Afrodite Test"); |
143 | 56 | opt_context.set_help_enabled (true); | 57 | opt_context.set_help_enabled (true); |
144 | @@ -60,12 +61,119 @@ | |||
145 | 60 | } catch (Error err) { | 61 | } catch (Error err) { |
146 | 61 | error (_("parsing options")); | 62 | error (_("parsing options")); |
147 | 62 | } | 63 | } |
151 | 63 | 64 | ||
149 | 64 | var engine = new Afrodite.CompletionEngine ("afrodite-test-engine"); | ||
150 | 65 | |||
152 | 66 | if (option_repeat == 0) | 65 | if (option_repeat == 0) |
153 | 67 | option_repeat = 1; | 66 | option_repeat = 1; |
155 | 68 | 67 | ||
156 | 68 | parse (); | ||
157 | 69 | _loop = new MainLoop(); | ||
158 | 70 | _loop.run(); | ||
159 | 71 | return 0; | ||
160 | 72 | } | ||
161 | 73 | |||
162 | 74 | private void on_begin_parsing (CompletionEngine engine) | ||
163 | 75 | { | ||
164 | 76 | print ("\nAfrodite engine is parsing sources\n"); | ||
165 | 77 | } | ||
166 | 78 | private void on_end_parsing (CompletionEngine engine) | ||
167 | 79 | { | ||
168 | 80 | print ("\nAfrodite engine end parsing sources\n"); | ||
169 | 81 | _loop.quit (); | ||
170 | 82 | dump (engine); | ||
171 | 83 | } | ||
172 | 84 | |||
173 | 85 | private void dump (CompletionEngine engine) | ||
174 | 86 | { | ||
175 | 87 | print (": done\n\n"); | ||
176 | 88 | print ("Looking for '%s' %d,%d\n\nDump follows:\n", option_symbol_name, option_line, option_column); | ||
177 | 89 | while (true) | ||
178 | 90 | { | ||
179 | 91 | // dumping tree (just a debug facility) | ||
180 | 92 | var dumper = new Afrodite.AstDumper (); | ||
181 | 93 | dumper.dump (engine.ast, option_namespace); | ||
182 | 94 | print ("\n"); | ||
183 | 95 | |||
184 | 96 | // Query the AST | ||
185 | 97 | if (option_visible_symbols != null) { | ||
186 | 98 | var source = engine.ast.lookup_source_file (option_visible_symbols); | ||
187 | 99 | if (source != null) { | ||
188 | 100 | // get the source node at this position | ||
189 | 101 | var s = engine.ast.get_symbol_for_source_and_position (source, option_line, option_column); | ||
190 | 102 | if (s != null) { | ||
191 | 103 | Vala.List<Symbol> syms = null; | ||
192 | 104 | syms = engine.ast.lookup_visible_symbols_from_symbol (s, option_filter); | ||
193 | 105 | print ("Symbols found: %d\n", syms.size); | ||
194 | 106 | foreach (Symbol sym in syms) { | ||
195 | 107 | print (" from %s: %s\n", sym.parent == null ? "<root>" : sym.parent.fully_qualified_name, Utils.unescape_xml_string (sym.description)); | ||
196 | 108 | } | ||
197 | 109 | } else { | ||
198 | 110 | print ("no symbol found for position: %d-%d\n", option_line, option_column); | ||
199 | 111 | } | ||
200 | 112 | } else { | ||
201 | 113 | print ("source file not found: %s\n", option_visible_symbols); | ||
202 | 114 | } | ||
203 | 115 | } else if (option_symbol_name != null) { | ||
204 | 116 | // Setup query options | ||
205 | 117 | QueryOptions options = QueryOptions.standard (); | ||
206 | 118 | options.auto_member_binding_mode = true; | ||
207 | 119 | options.compare_mode = CompareMode.EXACT; | ||
208 | 120 | options.access = Afrodite.SymbolAccessibility.ANY; | ||
209 | 121 | options.binding = Afrodite.MemberBinding.ANY; | ||
210 | 122 | |||
211 | 123 | QueryResult sym = null; | ||
212 | 124 | sym = engine.ast.get_symbol_type_for_name_and_path (options, option_symbol_name, option_files[0], option_line, option_column); | ||
213 | 125 | print ("The type for '%s' is: ", option_symbol_name); | ||
214 | 126 | if (!sym.is_empty) { | ||
215 | 127 | foreach (ResultItem item in sym.children) { | ||
216 | 128 | print ("%s\n Childs:\n", Utils.unescape_xml_string (item.symbol.description)); | ||
217 | 129 | if (item.symbol.has_children) { | ||
218 | 130 | int count = 0; | ||
219 | 131 | // print an excerpt of the child symbols | ||
220 | 132 | foreach (var child in item.symbol.children) { | ||
221 | 133 | print (" %s\n", Utils.unescape_xml_string (child.description)); | ||
222 | 134 | count++; | ||
223 | 135 | if (count == 6) { | ||
224 | 136 | print (" ......\n"); | ||
225 | 137 | break; | ||
226 | 138 | } | ||
227 | 139 | } | ||
228 | 140 | if (count < 6 && item.symbol.has_base_types) { | ||
229 | 141 | foreach (var base_item in item.symbol.base_types) { | ||
230 | 142 | if (base_item.unresolved || !base_item.symbol.has_children) | ||
231 | 143 | continue; | ||
232 | 144 | |||
233 | 145 | foreach (var child in base_item.symbol.children) { | ||
234 | 146 | print (" %s\n", Utils.unescape_xml_string (child.description)); | ||
235 | 147 | count++; | ||
236 | 148 | if (count == 6) | ||
237 | 149 | break; | ||
238 | 150 | } | ||
239 | 151 | |||
240 | 152 | if (count == 6) { | ||
241 | 153 | print (" ......\n"); | ||
242 | 154 | break; | ||
243 | 155 | } | ||
244 | 156 | } | ||
245 | 157 | } | ||
246 | 158 | } | ||
247 | 159 | } | ||
248 | 160 | } else { | ||
249 | 161 | print ("unresolved :(\n"); | ||
250 | 162 | } | ||
251 | 163 | } | ||
252 | 164 | break; | ||
253 | 165 | } | ||
254 | 166 | |||
255 | 167 | print ("done\n"); | ||
256 | 168 | } | ||
257 | 169 | |||
258 | 170 | private void parse () { | ||
259 | 171 | int i = 0; | ||
260 | 172 | |||
261 | 173 | _engine = new Afrodite.CompletionEngine ("afrodite-test-engine"); | ||
262 | 174 | _engine.begin_parsing.connect (this.on_begin_parsing); | ||
263 | 175 | _engine.end_parsing.connect (this.on_end_parsing); | ||
264 | 176 | |||
265 | 69 | for(int repeat = 0; repeat < option_repeat; repeat++) { | 177 | for(int repeat = 0; repeat < option_repeat; repeat++) { |
266 | 70 | print ("Adding sources (%d):\n", repeat); | 178 | print ("Adding sources (%d):\n", repeat); |
267 | 71 | i = 0; | 179 | i = 0; |
268 | @@ -82,118 +190,17 @@ | |||
269 | 82 | } | 190 | } |
270 | 83 | source.content = buffer; | 191 | source.content = buffer; |
271 | 84 | source.path = "live-buffer.vala"; | 192 | source.path = "live-buffer.vala"; |
273 | 85 | engine.queue_source (source); | 193 | _engine.queue_source (source); |
274 | 86 | } else { | 194 | } else { |
380 | 87 | engine.queue_sourcefile (filename); | 195 | _engine.queue_sourcefile (filename); |
381 | 88 | } | 196 | } |
382 | 89 | i++; | 197 | i++; |
383 | 90 | } | 198 | } |
384 | 91 | 199 | } | |
280 | 92 | print ("\nAfrodite engine is parsing sources (%d)", repeat); | ||
281 | 93 | // Wait for the engine to complete the parsing | ||
282 | 94 | i = 0; | ||
283 | 95 | while (engine.is_parsing) | ||
284 | 96 | { | ||
285 | 97 | if (i % 10 == 0) | ||
286 | 98 | print ("."); | ||
287 | 99 | Thread.usleep (1 * 250000); | ||
288 | 100 | i++; | ||
289 | 101 | } | ||
290 | 102 | } | ||
291 | 103 | |||
292 | 104 | Afrodite.Ast ast; | ||
293 | 105 | print (": done\n\n"); | ||
294 | 106 | print ("Looking for '%s' %d,%d\n\nDump follows:\n", option_symbol_name, option_line, option_column); | ||
295 | 107 | while (true) | ||
296 | 108 | { | ||
297 | 109 | // try to acquire ast | ||
298 | 110 | if (engine.try_acquire_ast (out ast)) { | ||
299 | 111 | // dumping tree (just a debug facility) | ||
300 | 112 | var dumper = new Afrodite.AstDumper (); | ||
301 | 113 | dumper.dump (ast, option_namespace); | ||
302 | 114 | print ("\n"); | ||
303 | 115 | |||
304 | 116 | // Query the AST | ||
305 | 117 | if (option_visible_symbols != null) { | ||
306 | 118 | var source = ast.lookup_source_file (option_visible_symbols); | ||
307 | 119 | if (source != null) { | ||
308 | 120 | // get the source node at this position | ||
309 | 121 | var s = ast.get_symbol_for_source_and_position (source, option_line, option_column); | ||
310 | 122 | if (s != null) { | ||
311 | 123 | Vala.List<Symbol> syms = null; | ||
312 | 124 | syms = ast.lookup_visible_symbols_from_symbol (s, option_filter); | ||
313 | 125 | print ("Symbols found: %d\n", syms.size); | ||
314 | 126 | foreach (Symbol sym in syms) { | ||
315 | 127 | print (" from %s: %s\n", sym.parent == null ? "<root>" : sym.parent.fully_qualified_name, Utils.unescape_xml_string (sym.description)); | ||
316 | 128 | } | ||
317 | 129 | } else { | ||
318 | 130 | print ("no symbol found for position: %d-%d\n", option_line, option_column); | ||
319 | 131 | } | ||
320 | 132 | } else { | ||
321 | 133 | print ("source file not found: %s\n", option_visible_symbols); | ||
322 | 134 | } | ||
323 | 135 | } else if (option_symbol_name != null) { | ||
324 | 136 | // Setup query options | ||
325 | 137 | QueryOptions options = QueryOptions.standard (); | ||
326 | 138 | options.auto_member_binding_mode = true; | ||
327 | 139 | options.compare_mode = CompareMode.EXACT; | ||
328 | 140 | options.access = Afrodite.SymbolAccessibility.ANY; | ||
329 | 141 | options.binding = Afrodite.MemberBinding.ANY; | ||
330 | 142 | |||
331 | 143 | QueryResult sym = null; | ||
332 | 144 | sym = ast.get_symbol_type_for_name_and_path (options, option_symbol_name, option_files[0], option_line, option_column); | ||
333 | 145 | print ("The type for '%s' is: ", option_symbol_name); | ||
334 | 146 | if (!sym.is_empty) { | ||
335 | 147 | foreach (ResultItem item in sym.children) { | ||
336 | 148 | print ("%s\n Childs:\n", Utils.unescape_xml_string (item.symbol.description)); | ||
337 | 149 | if (item.symbol.has_children) { | ||
338 | 150 | int count = 0; | ||
339 | 151 | // print an excerpt of the child symbols | ||
340 | 152 | foreach (var child in item.symbol.children) { | ||
341 | 153 | print (" %s\n", Utils.unescape_xml_string (child.description)); | ||
342 | 154 | count++; | ||
343 | 155 | if (count == 6) { | ||
344 | 156 | print (" ......\n"); | ||
345 | 157 | break; | ||
346 | 158 | } | ||
347 | 159 | } | ||
348 | 160 | if (count < 6 && item.symbol.has_base_types) { | ||
349 | 161 | foreach (var base_item in item.symbol.base_types) { | ||
350 | 162 | if (base_item.unresolved || !base_item.symbol.has_children) | ||
351 | 163 | continue; | ||
352 | 164 | |||
353 | 165 | foreach (var child in base_item.symbol.children) { | ||
354 | 166 | print (" %s\n", Utils.unescape_xml_string (child.description)); | ||
355 | 167 | count++; | ||
356 | 168 | if (count == 6) | ||
357 | 169 | break; | ||
358 | 170 | } | ||
359 | 171 | |||
360 | 172 | if (count == 6) { | ||
361 | 173 | print (" ......\n"); | ||
362 | 174 | break; | ||
363 | 175 | } | ||
364 | 176 | } | ||
365 | 177 | } | ||
366 | 178 | } | ||
367 | 179 | } | ||
368 | 180 | } else { | ||
369 | 181 | print ("unresolved :(\n"); | ||
370 | 182 | result = 1; | ||
371 | 183 | } | ||
372 | 184 | } | ||
373 | 185 | engine.release_ast (ast); | ||
374 | 186 | break; | ||
375 | 187 | } | ||
376 | 188 | } | ||
377 | 189 | |||
378 | 190 | print ("done\n"); | ||
379 | 191 | return result; | ||
385 | 192 | } | 200 | } |
386 | 193 | 201 | ||
387 | 194 | static int main (string[] args) { | 202 | static int main (string[] args) { |
388 | 195 | var application = new Application (); | 203 | var application = new Application (); |
391 | 196 | application.run (args); | 204 | return application.run (args); |
390 | 197 | return 0; | ||
392 | 198 | } | 205 | } |
393 | 199 | } | 206 | } |
394 | 200 | 207 | ||
395 | === modified file 'plugins/completion/afrodite-provider/afrodite/ast.vala' | |||
396 | --- plugins/completion/afrodite-provider/afrodite/ast.vala 2010-10-14 16:01:50 +0000 | |||
397 | +++ plugins/completion/afrodite-provider/afrodite/ast.vala 2011-03-10 19:26:24 +0000 | |||
398 | @@ -26,32 +26,17 @@ | |||
399 | 26 | { | 26 | { |
400 | 27 | public class Ast | 27 | public class Ast |
401 | 28 | { | 28 | { |
402 | 29 | |||
403 | 30 | #if DEBUG | ||
404 | 31 | // debug utility to dump leaked symbols when destroying a source file | ||
405 | 32 | public static Vala.List<unowned Symbol> leaked_symbols = new Vala.ArrayList<unowned Symbol>(); | ||
406 | 33 | #endif | ||
407 | 34 | public Vala.HashMap<string, unowned Symbol> symbols = new Vala.HashMap <string, unowned Symbol>(GLib.str_hash, GLib.str_equal); | 29 | public Vala.HashMap<string, unowned Symbol> symbols = new Vala.HashMap <string, unowned Symbol>(GLib.str_hash, GLib.str_equal); |
409 | 35 | 30 | public Vala.List<unowned Symbol> unresolved_symbols = new Vala.ArrayList<unowned Symbol>(); | |
410 | 31 | |||
411 | 36 | private Symbol _root = new Symbol (null, null); | 32 | private Symbol _root = new Symbol (null, null); |
412 | 37 | 33 | ||
413 | 38 | ~Ast () | 34 | ~Ast () |
414 | 39 | { | 35 | { |
415 | 40 | Utils.trace ("Ast destroy"); | 36 | Utils.trace ("Ast destroy"); |
416 | 41 | #if DEBUG | ||
417 | 42 | Utils.trace (" symbol count before destroy %d", leaked_symbols.size); | ||
418 | 43 | #endif | ||
419 | 44 | // destroy the root symbol | 37 | // destroy the root symbol |
420 | 45 | _root = null; | 38 | _root = null; |
421 | 46 | source_files = null;// source have to be destroyes after root symbol | 39 | source_files = null;// source have to be destroyes after root symbol |
422 | 47 | |||
423 | 48 | #if DEBUG | ||
424 | 49 | Utils.trace (" symbol count after destroy %d", leaked_symbols.size); | ||
425 | 50 | if (leaked_symbols.size > 0) { | ||
426 | 51 | this.dump_leaks (); | ||
427 | 52 | } | ||
428 | 53 | #endif | ||
429 | 54 | |||
430 | 55 | Utils.trace ("Ast destroyed"); | 40 | Utils.trace ("Ast destroyed"); |
431 | 56 | } | 41 | } |
432 | 57 | 42 | ||
433 | @@ -69,11 +54,11 @@ | |||
434 | 69 | 54 | ||
435 | 70 | public Vala.List<SourceFile> source_files { get; set; } | 55 | public Vala.List<SourceFile> source_files { get; set; } |
436 | 71 | 56 | ||
438 | 72 | public Symbol? lookup (string fully_qualified_name, out Symbol? parent) | 57 | public Symbol? lookup (string fully_qualified_name) |
439 | 73 | { | 58 | { |
440 | 74 | Symbol result = null; | 59 | Symbol result = null; |
441 | 75 | 60 | ||
443 | 76 | parent = _root; | 61 | Symbol parent = _root; |
444 | 77 | if (_root.has_children) { | 62 | if (_root.has_children) { |
445 | 78 | result = lookup_symbol (fully_qualified_name, _root, ref parent, CompareMode.EXACT); | 63 | result = lookup_symbol (fully_qualified_name, _root, ref parent, CompareMode.EXACT); |
446 | 79 | } | 64 | } |
447 | @@ -148,7 +133,6 @@ | |||
448 | 148 | */ | 133 | */ |
449 | 149 | 134 | ||
450 | 150 | foreach (SourceFile file in source_files) { | 135 | foreach (SourceFile file in source_files) { |
451 | 151 | |||
452 | 152 | if (file.filename == filename) { | 136 | if (file.filename == filename) { |
453 | 153 | return file; | 137 | return file; |
454 | 154 | } | 138 | } |
455 | @@ -582,10 +566,11 @@ | |||
456 | 582 | // search in using directives | 566 | // search in using directives |
457 | 583 | if (source.has_using_directives) { | 567 | if (source.has_using_directives) { |
458 | 584 | foreach (DataType u in source.using_directives) { | 568 | foreach (DataType u in source.using_directives) { |
462 | 585 | Symbol parent; | 569 | |
463 | 586 | 570 | ||
464 | 587 | sym = lookup (u.type_name, out parent); | 571 | sym = lookup (u.type_name); |
465 | 588 | if (sym != null) { | 572 | if (sym != null) { |
466 | 573 | Symbol parent = sym.parent; | ||
467 | 589 | if (compare_symbol_names (sym.name, name, mode)) { | 574 | if (compare_symbol_names (sym.name, name, mode)) { |
468 | 590 | // is a reference to a namespace | 575 | // is a reference to a namespace |
469 | 591 | return sym; | 576 | return sym; |
470 | @@ -606,7 +591,7 @@ | |||
471 | 606 | public Symbol? get_symbol_for_source_and_position (SourceFile source, int line, int column) | 591 | public Symbol? get_symbol_for_source_and_position (SourceFile source, int line, int column) |
472 | 607 | { | 592 | { |
473 | 608 | Symbol result = null; | 593 | Symbol result = null; |
475 | 609 | SourceReference result_sr = null; | 594 | unowned SourceReference result_sr = null; |
476 | 610 | 595 | ||
477 | 611 | if (source.has_symbols) { | 596 | if (source.has_symbols) { |
478 | 612 | // base 0 | 597 | // base 0 |
479 | @@ -638,19 +623,5 @@ | |||
480 | 638 | 623 | ||
481 | 639 | return result; | 624 | return result; |
482 | 640 | } | 625 | } |
483 | 641 | |||
484 | 642 | #if DEBUG | ||
485 | 643 | private void dump_leaks () | ||
486 | 644 | { | ||
487 | 645 | foreach (Symbol s in leaked_symbols) { | ||
488 | 646 | Utils.trace (" -- leaked symbol %s (%p), parent %s (%p), generic_parent %s (%p) childs %d, refcount %u", | ||
489 | 647 | s.fully_qualified_name, s, | ||
490 | 648 | s.parent == null ? "null" : s.parent.fully_qualified_name, s.parent, | ||
491 | 649 | s.generic_parent == null ? "null" : s.generic_parent.fully_qualified_name, s.generic_parent, | ||
492 | 650 | s.has_children ? s.children.size : 0, | ||
493 | 651 | s.ref_count); | ||
494 | 652 | } | ||
495 | 653 | } | ||
496 | 654 | #endif | ||
497 | 655 | } | 626 | } |
498 | 656 | } | 627 | } |
499 | 657 | 628 | ||
500 | === modified file 'plugins/completion/afrodite-provider/afrodite/astdumper.vala' | |||
501 | --- plugins/completion/afrodite-provider/afrodite/astdumper.vala 2010-09-03 21:40:48 +0000 | |||
502 | +++ plugins/completion/afrodite-provider/afrodite/astdumper.vala 2011-03-10 19:26:24 +0000 | |||
503 | @@ -140,7 +140,7 @@ | |||
504 | 140 | inc_pad (); | 140 | inc_pad (); |
505 | 141 | print ("%slocal variables\n", pad); | 141 | print ("%slocal variables\n", pad); |
506 | 142 | foreach (DataType local in symbol.local_variables) { | 142 | foreach (DataType local in symbol.local_variables) { |
508 | 143 | var sr = local.source_reference; | 143 | unowned SourceReference sr = local.source_reference; |
509 | 144 | print ("%s %s - [(%d - %d) %s]\n", | 144 | print ("%s %s - [(%d - %d) %s]\n", |
510 | 145 | pad, | 145 | pad, |
511 | 146 | Utils.unescape_xml_string (local.description), | 146 | Utils.unescape_xml_string (local.description), |
512 | 147 | 147 | ||
513 | === modified file 'plugins/completion/afrodite-provider/afrodite/astmerger.vala' | |||
514 | --- plugins/completion/afrodite-provider/afrodite/astmerger.vala 2010-12-30 07:38:50 +0000 | |||
515 | +++ plugins/completion/afrodite-provider/afrodite/astmerger.vala 2011-03-10 19:26:24 +0000 | |||
516 | @@ -28,40 +28,135 @@ | |||
517 | 28 | { | 28 | { |
518 | 29 | Afrodite.Symbol _current = null; | 29 | Afrodite.Symbol _current = null; |
519 | 30 | Afrodite.DataType _current_type = null; | 30 | Afrodite.DataType _current_type = null; |
521 | 31 | Afrodite.SourceReference _current_sr = null; | 31 | unowned Afrodite.SourceReference _current_sr = null; |
522 | 32 | Afrodite.SourceFile _source_file = null; | 32 | Afrodite.SourceFile _source_file = null; |
523 | 33 | Afrodite.DataType _inferred_type = null; | 33 | Afrodite.DataType _inferred_type = null; |
524 | 34 | Vala.Literal _last_literal = null; | 34 | Vala.Literal _last_literal = null; |
525 | 35 | 35 | ||
526 | 36 | string _vala_symbol_fqn = null; | 36 | string _vala_symbol_fqn = null; |
527 | 37 | bool _merge_glib = true; | 37 | bool _merge_glib = true; |
530 | 38 | int _child_count = 0; | 38 | |
529 | 39 | |||
531 | 40 | private Afrodite.Ast _ast = null; | 39 | private Afrodite.Ast _ast = null; |
533 | 41 | 40 | ||
534 | 42 | public AstMerger (Afrodite.Ast ast) | 41 | public AstMerger (Afrodite.Ast ast) |
535 | 43 | { | 42 | { |
536 | 44 | this._ast = ast; | 43 | this._ast = ast; |
537 | 45 | } | 44 | } |
538 | 46 | 45 | ||
540 | 47 | public void merge_vala_context (Vala.SourceFile source, CodeContext context, bool merge_glib = false) | 46 | public async void merge_vala_context (Vala.SourceFile source, CodeContext context, bool merge_glib = false) |
541 | 48 | { | 47 | { |
542 | 49 | _merge_glib = merge_glib; | 48 | _merge_glib = merge_glib; |
543 | 50 | _vala_symbol_fqn = null; | 49 | _vala_symbol_fqn = null; |
544 | 51 | _current_type = null; | 50 | _current_type = null; |
545 | 52 | _child_count = 0; | ||
546 | 53 | _current = _ast.root; | 51 | _current = _ast.root; |
547 | 54 | assert (_ast.lookup_source_file (source.filename) == null); | 52 | assert (_ast.lookup_source_file (source.filename) == null); |
548 | 55 | 53 | ||
549 | 56 | //debug ("COMPLETING FILE %s", source.filename); | 54 | //debug ("COMPLETING FILE %s", source.filename); |
550 | 57 | _source_file = _ast.add_source_file (source.filename); | 55 | _source_file = _ast.add_source_file (source.filename); |
551 | 58 | foreach (UsingDirective u in source.current_using_directives) { | 56 | foreach (UsingDirective u in source.current_using_directives) { |
558 | 59 | _source_file.add_using_directive (u.namespace_symbol.get_full_name ()); | 57 | _source_file.add_using_directive (u.namespace_symbol.to_string ()); |
559 | 60 | } | 58 | } |
560 | 61 | context.root.accept_children (this); | 59 | yield visit_namespace_sliced (context.root); |
561 | 62 | } | 60 | } |
562 | 63 | 61 | ||
563 | 64 | public void remove_source_filename (string filename) | 62 | public async void visit_namespace_sliced (Namespace ns) |
564 | 63 | { | ||
565 | 64 | var prev_vala_fqn = _vala_symbol_fqn; | ||
566 | 65 | var prev = _current; | ||
567 | 66 | unowned SourceReference prev_sr = _current_sr; | ||
568 | 67 | |||
569 | 68 | if (ns.name != null) | ||
570 | 69 | _current = visit_symbol (ns, out _current_sr); | ||
571 | 70 | |||
572 | 71 | foreach (Enum en in ns.get_enums ()) { | ||
573 | 72 | en.accept (this); | ||
574 | 73 | } | ||
575 | 74 | |||
576 | 75 | foreach (ErrorDomain edomain in ns.get_error_domains ()) { | ||
577 | 76 | edomain.accept (this); | ||
578 | 77 | } | ||
579 | 78 | |||
580 | 79 | foreach (Vala.Namespace n in ns.get_namespaces ()) { | ||
581 | 80 | yield visit_namespace_sliced (n); | ||
582 | 81 | } | ||
583 | 82 | |||
584 | 83 | foreach (Vala.Class cl in ns.get_classes ()) { | ||
585 | 84 | yield visit_class_sliced (cl); | ||
586 | 85 | } | ||
587 | 86 | |||
588 | 87 | foreach (Interface iface in ns.get_interfaces ()) { | ||
589 | 88 | yield visit_interface_sliced (iface); | ||
590 | 89 | } | ||
591 | 90 | |||
592 | 91 | foreach (Struct st in ns.get_structs ()) { | ||
593 | 92 | yield visit_struct_sliced (st); | ||
594 | 93 | } | ||
595 | 94 | |||
596 | 95 | foreach (Delegate d in ns.get_delegates ()) { | ||
597 | 96 | d.accept (this); | ||
598 | 97 | } | ||
599 | 98 | |||
600 | 99 | foreach (Constant c in ns.get_constants ()) { | ||
601 | 100 | c.accept (this); | ||
602 | 101 | } | ||
603 | 102 | |||
604 | 103 | foreach (Field f in ns.get_fields ()) { | ||
605 | 104 | f.accept (this); | ||
606 | 105 | } | ||
607 | 106 | |||
608 | 107 | foreach (Method m in ns.get_methods ()) { | ||
609 | 108 | m.accept (this); | ||
610 | 109 | } | ||
611 | 110 | |||
612 | 111 | _current = prev; | ||
613 | 112 | _current_sr = prev_sr; | ||
614 | 113 | _vala_symbol_fqn = prev_vala_fqn; | ||
615 | 114 | } | ||
616 | 115 | |||
617 | 116 | public async void visit_class_sliced (Class c) | ||
618 | 117 | { | ||
619 | 118 | visit_class (c); | ||
620 | 119 | } | ||
621 | 120 | |||
622 | 121 | public async void visit_struct_sliced (Struct st) | ||
623 | 122 | { | ||
624 | 123 | visit_struct (st); | ||
625 | 124 | } | ||
626 | 125 | |||
627 | 126 | public async void visit_interface_sliced (Interface iface) | ||
628 | 127 | { | ||
629 | 128 | visit_interface (iface); | ||
630 | 129 | } | ||
631 | 130 | |||
632 | 131 | public override void visit_class (Class c) | ||
633 | 132 | { | ||
634 | 133 | var prev_vala_fqn = _vala_symbol_fqn; | ||
635 | 134 | var prev = _current; | ||
636 | 135 | unowned SourceReference prev_sr = _current_sr; | ||
637 | 136 | |||
638 | 137 | _current = visit_symbol (c, out _current_sr); | ||
639 | 138 | _current.is_abstract = c.is_abstract; | ||
640 | 139 | c.accept_children (this); | ||
641 | 140 | |||
642 | 141 | _current = prev; | ||
643 | 142 | _current_sr = prev_sr; | ||
644 | 143 | _vala_symbol_fqn = prev_vala_fqn; | ||
645 | 144 | } | ||
646 | 145 | |||
647 | 146 | public override void visit_struct (Struct s) | ||
648 | 147 | { | ||
649 | 148 | var prev_vala_fqn = _vala_symbol_fqn; | ||
650 | 149 | var prev = _current; | ||
651 | 150 | unowned SourceReference prev_sr = _current_sr; | ||
652 | 151 | |||
653 | 152 | _current = visit_symbol (s, out _current_sr); | ||
654 | 153 | s.accept_children (this); | ||
655 | 154 | _current = prev; | ||
656 | 155 | _current_sr = prev_sr; | ||
657 | 156 | _vala_symbol_fqn = prev_vala_fqn; | ||
658 | 157 | } | ||
659 | 158 | |||
660 | 159 | public async void remove_source_filename (string filename) | ||
661 | 65 | { | 160 | { |
662 | 66 | var source = _ast.lookup_source_file (filename); | 161 | var source = _ast.lookup_source_file (filename); |
663 | 67 | assert (source != null); | 162 | assert (source != null); |
664 | @@ -69,65 +164,62 @@ | |||
665 | 69 | _ast.remove_source (source); | 164 | _ast.remove_source (source); |
666 | 70 | } | 165 | } |
667 | 71 | 166 | ||
669 | 72 | private Afrodite.Symbol visit_symbol (Vala.Symbol s, out Afrodite.SourceReference source_reference) | 167 | private Afrodite.Symbol visit_symbol (Vala.Symbol s, out unowned Afrodite.SourceReference source_reference) |
670 | 73 | { | 168 | { |
671 | 74 | Afrodite.Symbol symbol; | 169 | Afrodite.Symbol symbol; |
672 | 75 | 170 | ||
673 | 76 | set_fqn (s.name); | 171 | set_fqn (s.name); |
674 | 77 | //symbol = _ast.lookup (_vala_symbol_fqn, out parent); | ||
675 | 78 | //assert (parent != null); | ||
676 | 79 | symbol = _ast.symbols.@get (_vala_symbol_fqn); | ||
677 | 80 | 172 | ||
679 | 81 | if (symbol == null) { | 173 | //NOTE: usually we should always add symbols but |
680 | 174 | // we should merge namespaces content. | ||
681 | 175 | // This must be changed whenever vala will support | ||
682 | 176 | // partial classes. | ||
683 | 177 | if (s.type_name != "ValaNamespace") { | ||
684 | 82 | symbol = add_symbol (s, out source_reference); | 178 | symbol = add_symbol (s, out source_reference); |
685 | 83 | //Utils.trace ("adding %s to source %s", symbol.fully_qualified_name, _source_file.filename); | ||
686 | 84 | _current.add_child (symbol); | 179 | _current.add_child (symbol); |
687 | 85 | } else { | 180 | } else { |
696 | 86 | Afrodite.Symbol parent = symbol.parent; | 181 | symbol = _ast.lookup (_vala_symbol_fqn); |
697 | 87 | //NOTE: see if we should replace the symbol | 182 | if (symbol == null) { |
690 | 88 | // we should replace it if is not a namespace | ||
691 | 89 | // this can change whenever vala will support | ||
692 | 90 | // partial classes | ||
693 | 91 | bool replace = s.type_name != "ValaNamespace"; | ||
694 | 92 | if (replace) { | ||
695 | 93 | parent.remove_child (symbol); | ||
698 | 94 | symbol = add_symbol (s, out source_reference); | 183 | symbol = add_symbol (s, out source_reference); |
700 | 95 | parent.add_child (symbol); | 184 | //Utils.trace ("adding %s to source %s", symbol.fully_qualified_name, _source_file.filename); |
701 | 185 | _current.add_child (symbol); | ||
702 | 96 | } else { | 186 | } else { |
703 | 187 | source_reference = symbol.lookup_source_reference_filename (_source_file.filename); | ||
704 | 97 | // add one more source reference to the symbol | 188 | // add one more source reference to the symbol |
705 | 98 | source_reference = symbol.lookup_source_reference_filename (_source_file.filename); | ||
706 | 99 | if (source_reference == null) { | 189 | if (source_reference == null) { |
709 | 100 | source_reference = create_source_reference (s); | 190 | var sr = create_source_reference (s); |
710 | 101 | symbol.add_source_reference (source_reference); | 191 | symbol.add_source_reference (sr); |
711 | 192 | source_reference = sr; | ||
712 | 102 | //Utils.trace ("adding source reference %s to source %s", symbol.fully_qualified_name, _source_file.filename); | 193 | //Utils.trace ("adding source reference %s to source %s", symbol.fully_qualified_name, _source_file.filename); |
713 | 103 | _source_file.add_symbol (symbol); | 194 | _source_file.add_symbol (symbol); |
714 | 104 | } else { | 195 | } else { |
716 | 105 | warning ("two sources with the same name were merged: %s", _source_file.filename); | 196 | warning ("two sources with the same name were merged %s: %s", symbol.fully_qualified_name, _source_file.filename); |
717 | 106 | } | 197 | } |
718 | 107 | } | 198 | } |
719 | 108 | } | 199 | } |
720 | 109 | |||
721 | 110 | return symbol; | 200 | return symbol; |
722 | 111 | } | 201 | } |
723 | 112 | 202 | ||
725 | 113 | private Afrodite.Symbol add_symbol (Vala.Symbol s, out Afrodite.SourceReference source_ref, int last_line = 0, int last_column = 0) | 203 | private Afrodite.Symbol add_symbol (Vala.Symbol s, out unowned Afrodite.SourceReference source_ref, int last_line = 0, int last_column = 0) |
726 | 114 | { | 204 | { |
727 | 115 | var symbol = new Afrodite.Symbol (_vala_symbol_fqn, s.type_name); | 205 | var symbol = new Afrodite.Symbol (_vala_symbol_fqn, s.type_name); |
728 | 116 | if (symbol.lookup_source_reference_filename (_source_file.filename) == null) { | 206 | if (symbol.lookup_source_reference_filename (_source_file.filename) == null) { |
731 | 117 | source_ref = create_source_reference (s, last_line, last_column); | 207 | var sr = create_source_reference (s, last_line, last_column); |
732 | 118 | symbol.add_source_reference (source_ref); | 208 | symbol.add_source_reference (sr); |
733 | 209 | source_ref = sr; | ||
734 | 119 | } | 210 | } |
735 | 120 | symbol.access = get_vala_symbol_access (s.access); | 211 | symbol.access = get_vala_symbol_access (s.access); |
736 | 121 | _source_file.add_symbol (symbol); | 212 | _source_file.add_symbol (symbol); |
737 | 122 | return symbol; | 213 | return symbol; |
738 | 123 | } | 214 | } |
739 | 124 | 215 | ||
741 | 125 | private Afrodite.Symbol add_codenode (string type_name, Vala.CodeNode c, out Afrodite.SourceReference source_ref, int last_line = 0, int last_column = 0) | 216 | private Afrodite.Symbol add_codenode (string type_name, Vala.CodeNode c, out unowned Afrodite.SourceReference source_ref, int last_line = 0, int last_column = 0) |
742 | 126 | { | 217 | { |
743 | 127 | var symbol = new Afrodite.Symbol (_vala_symbol_fqn, type_name); | 218 | var symbol = new Afrodite.Symbol (_vala_symbol_fqn, type_name); |
744 | 128 | if (symbol.lookup_source_reference_filename (_source_file.filename) == null) { | 219 | if (symbol.lookup_source_reference_filename (_source_file.filename) == null) { |
747 | 129 | source_ref = create_source_reference (c, last_line, last_column); | 220 | var sr = create_source_reference (c, last_line, last_column); |
748 | 130 | symbol.add_source_reference (source_ref); | 221 | symbol.add_source_reference (sr); |
749 | 222 | source_ref = sr; | ||
750 | 131 | } | 223 | } |
751 | 132 | symbol.access = Afrodite.SymbolAccessibility.PRIVATE; | 224 | symbol.access = Afrodite.SymbolAccessibility.PRIVATE; |
752 | 133 | _source_file.add_symbol (symbol); | 225 | _source_file.add_symbol (symbol); |
753 | @@ -198,58 +290,11 @@ | |||
754 | 198 | } | 290 | } |
755 | 199 | } | 291 | } |
756 | 200 | 292 | ||
757 | 201 | public override void visit_namespace (Namespace ns) | ||
758 | 202 | { | ||
759 | 203 | var prev_vala_fqn = _vala_symbol_fqn; | ||
760 | 204 | var prev = _current; | ||
761 | 205 | var prev_sr = _current_sr; | ||
762 | 206 | var prev_child_count = _child_count; | ||
763 | 207 | |||
764 | 208 | _current = visit_symbol (ns, out _current_sr); | ||
765 | 209 | ns.accept_children (this); | ||
766 | 210 | |||
767 | 211 | _child_count = prev_child_count; | ||
768 | 212 | _current = prev; | ||
769 | 213 | _current_sr = prev_sr; | ||
770 | 214 | _vala_symbol_fqn = prev_vala_fqn; | ||
771 | 215 | } | ||
772 | 216 | |||
773 | 217 | public override void visit_class (Class c) | ||
774 | 218 | { | ||
775 | 219 | _child_count++; | ||
776 | 220 | var prev_vala_fqn = _vala_symbol_fqn; | ||
777 | 221 | var prev = _current; | ||
778 | 222 | var prev_sr = _current_sr; | ||
779 | 223 | |||
780 | 224 | _current = visit_symbol (c, out _current_sr); | ||
781 | 225 | _current.is_abstract = c.is_abstract; | ||
782 | 226 | c.accept_children (this); | ||
783 | 227 | |||
784 | 228 | _current = prev; | ||
785 | 229 | _current_sr = prev_sr; | ||
786 | 230 | _vala_symbol_fqn = prev_vala_fqn; | ||
787 | 231 | } | ||
788 | 232 | |||
789 | 233 | public override void visit_struct (Struct s) | ||
790 | 234 | { | ||
791 | 235 | _child_count++; | ||
792 | 236 | var prev_vala_fqn = _vala_symbol_fqn; | ||
793 | 237 | var prev = _current; | ||
794 | 238 | var prev_sr = _current_sr; | ||
795 | 239 | |||
796 | 240 | _current = visit_symbol (s, out _current_sr); | ||
797 | 241 | s.accept_children (this); | ||
798 | 242 | _current = prev; | ||
799 | 243 | _current_sr = prev_sr; | ||
800 | 244 | _vala_symbol_fqn = prev_vala_fqn; | ||
801 | 245 | } | ||
802 | 246 | |||
803 | 247 | public override void visit_interface (Interface iface) | 293 | public override void visit_interface (Interface iface) |
804 | 248 | { | 294 | { |
805 | 249 | _child_count++; | ||
806 | 250 | var prev_vala_fqn = _vala_symbol_fqn; | 295 | var prev_vala_fqn = _vala_symbol_fqn; |
807 | 251 | var prev = _current; | 296 | var prev = _current; |
809 | 252 | var prev_sr = _current_sr; | 297 | unowned SourceReference prev_sr = _current_sr; |
810 | 253 | 298 | ||
811 | 254 | _current = visit_symbol (iface, out _current_sr); | 299 | _current = visit_symbol (iface, out _current_sr); |
812 | 255 | iface.accept_children (this); | 300 | iface.accept_children (this); |
813 | @@ -258,6 +303,7 @@ | |||
814 | 258 | _vala_symbol_fqn = prev_vala_fqn; | 303 | _vala_symbol_fqn = prev_vala_fqn; |
815 | 259 | } | 304 | } |
816 | 260 | 305 | ||
817 | 306 | /* | ||
818 | 261 | public override void visit_expression_statement (Vala.ExpressionStatement e) | 307 | public override void visit_expression_statement (Vala.ExpressionStatement e) |
819 | 262 | { | 308 | { |
820 | 263 | e.accept_children (this); | 309 | e.accept_children (this); |
821 | @@ -268,13 +314,17 @@ | |||
822 | 268 | //Utils.trace ("visit method call: %s", c.call.type_name); | 314 | //Utils.trace ("visit method call: %s", c.call.type_name); |
823 | 269 | c.accept_children (this); | 315 | c.accept_children (this); |
824 | 270 | } | 316 | } |
825 | 317 | */ | ||
826 | 271 | 318 | ||
827 | 272 | public override void visit_method (Method m) | 319 | public override void visit_method (Method m) |
828 | 273 | { | 320 | { |
830 | 274 | _child_count++; | 321 | //var timer = new Timer(); |
831 | 322 | //timer.start (); | ||
832 | 323 | //Utils.trace ("visit method %s", m.name); | ||
833 | 324 | |||
834 | 275 | var prev_vala_fqn = _vala_symbol_fqn; | 325 | var prev_vala_fqn = _vala_symbol_fqn; |
835 | 276 | var prev = _current; | 326 | var prev = _current; |
837 | 277 | var prev_sr = _current_sr; | 327 | unowned SourceReference prev_sr = _current_sr; |
838 | 278 | 328 | ||
839 | 279 | set_fqn (m.name); | 329 | set_fqn (m.name); |
840 | 280 | int last_line = 0; | 330 | int last_line = 0; |
841 | @@ -301,18 +351,30 @@ | |||
842 | 301 | 351 | ||
843 | 302 | _current = s; | 352 | _current = s; |
844 | 303 | visit_type_for_generics (m.return_type, s.return_type); | 353 | visit_type_for_generics (m.return_type, s.return_type); |
847 | 304 | m.accept_children (this); | 354 | //Utils.trace ("visit method (symbol) %s: %f", m.name, timer.elapsed()); |
848 | 305 | 355 | foreach (TypeParameter p in m.get_type_parameters ()) { | |
849 | 356 | p.accept (this); | ||
850 | 357 | } | ||
851 | 358 | //Utils.trace ("visit method (typeparam) %s: %f", m.name, timer.elapsed()); | ||
852 | 359 | foreach (Vala.Parameter param in m.get_parameters ()) { | ||
853 | 360 | param.accept (this); | ||
854 | 361 | } | ||
855 | 362 | //Utils.trace ("visit method (param) %s: %f", m.name, timer.elapsed()); | ||
856 | 363 | if (m.body != null) { | ||
857 | 364 | m.body.accept (this); | ||
858 | 365 | } | ||
859 | 366 | //Utils.trace ("visit method (body) %s: %f", m.name, timer.elapsed()); | ||
860 | 306 | _current = prev; | 367 | _current = prev; |
861 | 307 | _current_sr = prev_sr; | 368 | _current_sr = prev_sr; |
862 | 308 | _vala_symbol_fqn = prev_vala_fqn; | 369 | _vala_symbol_fqn = prev_vala_fqn; |
863 | 370 | //Utils.trace ("visit method %s: %f", m.name, timer.elapsed()); | ||
864 | 309 | } | 371 | } |
865 | 310 | 372 | ||
866 | 311 | public override void visit_creation_method (CreationMethod m) | 373 | public override void visit_creation_method (CreationMethod m) |
867 | 312 | { | 374 | { |
868 | 313 | var prev_vala_fqn = _vala_symbol_fqn; | 375 | var prev_vala_fqn = _vala_symbol_fqn; |
869 | 314 | var prev = _current; | 376 | var prev = _current; |
871 | 315 | var prev_sr = _current_sr; | 377 | unowned SourceReference prev_sr = _current_sr; |
872 | 316 | 378 | ||
873 | 317 | set_fqn (m.name); | 379 | set_fqn (m.name); |
874 | 318 | int last_line = 0; | 380 | int last_line = 0; |
875 | @@ -339,8 +401,18 @@ | |||
876 | 339 | 401 | ||
877 | 340 | _current = s; | 402 | _current = s; |
878 | 341 | visit_type_for_generics (m.return_type, s.return_type); | 403 | visit_type_for_generics (m.return_type, s.return_type); |
881 | 342 | m.accept_children (this); | 404 | foreach (TypeParameter p in m.get_type_parameters ()) { |
882 | 343 | 405 | p.accept (this); | |
883 | 406 | } | ||
884 | 407 | |||
885 | 408 | foreach (Vala.Parameter param in m.get_parameters ()) { | ||
886 | 409 | param.accept (this); | ||
887 | 410 | } | ||
888 | 411 | |||
889 | 412 | if (m.body != null) { | ||
890 | 413 | m.body.accept (this); | ||
891 | 414 | } | ||
892 | 415 | |||
893 | 344 | _current = prev; | 416 | _current = prev; |
894 | 345 | _current_sr = prev_sr; | 417 | _current_sr = prev_sr; |
895 | 346 | _vala_symbol_fqn = prev_vala_fqn; | 418 | _vala_symbol_fqn = prev_vala_fqn; |
896 | @@ -350,7 +422,7 @@ | |||
897 | 350 | { | 422 | { |
898 | 351 | var prev_vala_fqn = _vala_symbol_fqn; | 423 | var prev_vala_fqn = _vala_symbol_fqn; |
899 | 352 | var prev = _current; | 424 | var prev = _current; |
901 | 353 | var prev_sr = _current_sr; | 425 | unowned SourceReference prev_sr = _current_sr; |
902 | 354 | 426 | ||
903 | 355 | set_fqn ("constructor:%s".printf(_current.fully_qualified_name)); | 427 | set_fqn ("constructor:%s".printf(_current.fully_qualified_name)); |
904 | 356 | int last_line = 0; | 428 | int last_line = 0; |
905 | @@ -363,8 +435,9 @@ | |||
906 | 363 | _current.add_child (s); | 435 | _current.add_child (s); |
907 | 364 | 436 | ||
908 | 365 | _current = s; | 437 | _current = s; |
911 | 366 | m.accept_children (this); | 438 | if (m.body != null) { |
912 | 367 | 439 | m.body.accept (this); | |
913 | 440 | } | ||
914 | 368 | _current = prev; | 441 | _current = prev; |
915 | 369 | _current_sr = prev_sr; | 442 | _current_sr = prev_sr; |
916 | 370 | _vala_symbol_fqn = prev_vala_fqn; | 443 | _vala_symbol_fqn = prev_vala_fqn; |
917 | @@ -374,7 +447,7 @@ | |||
918 | 374 | { | 447 | { |
919 | 375 | var prev_vala_fqn = _vala_symbol_fqn; | 448 | var prev_vala_fqn = _vala_symbol_fqn; |
920 | 376 | var prev = _current; | 449 | var prev = _current; |
922 | 377 | var prev_sr = _current_sr; | 450 | unowned SourceReference prev_sr = _current_sr; |
923 | 378 | 451 | ||
924 | 379 | set_fqn ("destructor:%s".printf(_current.fully_qualified_name)); | 452 | set_fqn ("destructor:%s".printf(_current.fully_qualified_name)); |
925 | 380 | int last_line = 0; | 453 | int last_line = 0; |
926 | @@ -387,7 +460,10 @@ | |||
927 | 387 | _current.add_child (s); | 460 | _current.add_child (s); |
928 | 388 | 461 | ||
929 | 389 | _current = s; | 462 | _current = s; |
931 | 390 | m.accept_children (this); | 463 | if (m.body != null) { |
932 | 464 | m.body.accept (this); | ||
933 | 465 | } | ||
934 | 466 | |||
935 | 391 | _current = prev; | 467 | _current = prev; |
936 | 392 | _current_sr = prev_sr; | 468 | _current_sr = prev_sr; |
937 | 393 | _vala_symbol_fqn = prev_vala_fqn; | 469 | _vala_symbol_fqn = prev_vala_fqn; |
938 | @@ -397,7 +473,7 @@ | |||
939 | 397 | { | 473 | { |
940 | 398 | var prev_vala_fqn = _vala_symbol_fqn; | 474 | var prev_vala_fqn = _vala_symbol_fqn; |
941 | 399 | var prev = _current; | 475 | var prev = _current; |
943 | 400 | var prev_sr = _current_sr; | 476 | unowned SourceReference prev_sr = _current_sr; |
944 | 401 | 477 | ||
945 | 402 | set_fqn (ev.name); | 478 | set_fqn (ev.name); |
946 | 403 | var sym = add_symbol (ev, out _current_sr); | 479 | var sym = add_symbol (ev, out _current_sr); |
947 | @@ -412,16 +488,27 @@ | |||
948 | 412 | 488 | ||
949 | 413 | public override void visit_enum (Vala.Enum e) | 489 | public override void visit_enum (Vala.Enum e) |
950 | 414 | { | 490 | { |
951 | 415 | _child_count++; | ||
952 | 416 | var prev_vala_fqn = _vala_symbol_fqn; | 491 | var prev_vala_fqn = _vala_symbol_fqn; |
953 | 417 | var prev = _current; | 492 | var prev = _current; |
955 | 418 | var prev_sr = _current_sr; | 493 | unowned SourceReference prev_sr = _current_sr; |
956 | 419 | 494 | ||
957 | 420 | set_fqn (e.name); | 495 | set_fqn (e.name); |
958 | 421 | var s = add_symbol (e, out _current_sr); | 496 | var s = add_symbol (e, out _current_sr); |
959 | 422 | _current.add_child (s); | 497 | _current.add_child (s); |
960 | 423 | _current = s; | 498 | _current = s; |
962 | 424 | e.accept_children (this); | 499 | |
963 | 500 | foreach (Vala.EnumValue value in e.get_values ()) { | ||
964 | 501 | value.accept (this); | ||
965 | 502 | } | ||
966 | 503 | |||
967 | 504 | foreach (Method m in e.get_methods ()) { | ||
968 | 505 | m.accept (this); | ||
969 | 506 | } | ||
970 | 507 | |||
971 | 508 | foreach (Constant c in e.get_constants ()) { | ||
972 | 509 | c.accept (this); | ||
973 | 510 | } | ||
974 | 511 | |||
975 | 425 | _current = prev; | 512 | _current = prev; |
976 | 426 | _current_sr = prev_sr; | 513 | _current_sr = prev_sr; |
977 | 427 | _vala_symbol_fqn = prev_vala_fqn; | 514 | _vala_symbol_fqn = prev_vala_fqn; |
978 | @@ -429,16 +516,23 @@ | |||
979 | 429 | 516 | ||
980 | 430 | public override void visit_delegate (Delegate d) | 517 | public override void visit_delegate (Delegate d) |
981 | 431 | { | 518 | { |
982 | 432 | _child_count++; | ||
983 | 433 | var prev_vala_fqn = _vala_symbol_fqn; | 519 | var prev_vala_fqn = _vala_symbol_fqn; |
984 | 434 | var prev = _current; | 520 | var prev = _current; |
986 | 435 | var prev_sr = _current_sr; | 521 | unowned SourceReference prev_sr = _current_sr; |
987 | 436 | 522 | ||
988 | 437 | set_fqn (d.name); | 523 | set_fqn (d.name); |
989 | 438 | var sym = add_symbol (d, out _current_sr); | 524 | var sym = add_symbol (d, out _current_sr); |
990 | 525 | sym.return_type = new DataType (d.return_type.to_string ()); | ||
991 | 439 | _current.add_child (sym); | 526 | _current.add_child (sym); |
992 | 440 | _current = sym; | 527 | _current = sym; |
994 | 441 | d.accept_children (this); | 528 | |
995 | 529 | foreach (TypeParameter p in d.get_type_parameters ()) { | ||
996 | 530 | p.accept (this); | ||
997 | 531 | } | ||
998 | 532 | foreach (Vala.Parameter param in d.get_parameters ()) { | ||
999 | 533 | param.accept (this); | ||
1000 | 534 | } | ||
1001 | 535 | |||
1002 | 442 | _current = prev; | 536 | _current = prev; |
1003 | 443 | _current_sr = prev_sr; | 537 | _current_sr = prev_sr; |
1004 | 444 | _vala_symbol_fqn = prev_vala_fqn; | 538 | _vala_symbol_fqn = prev_vala_fqn; |
1005 | @@ -446,10 +540,9 @@ | |||
1006 | 446 | 540 | ||
1007 | 447 | public override void visit_signal (Vala.Signal s) | 541 | public override void visit_signal (Vala.Signal s) |
1008 | 448 | { | 542 | { |
1009 | 449 | _child_count++; | ||
1010 | 450 | var prev_vala_fqn = _vala_symbol_fqn; | 543 | var prev_vala_fqn = _vala_symbol_fqn; |
1011 | 451 | var prev = _current; | 544 | var prev = _current; |
1013 | 452 | var prev_sr = _current_sr; | 545 | unowned SourceReference prev_sr = _current_sr; |
1014 | 453 | 546 | ||
1015 | 454 | set_fqn (s.name); | 547 | set_fqn (s.name); |
1016 | 455 | var sym = add_symbol (s, out _current_sr); | 548 | var sym = add_symbol (s, out _current_sr); |
1017 | @@ -457,7 +550,16 @@ | |||
1018 | 457 | sym.is_virtual = s.is_virtual; | 550 | sym.is_virtual = s.is_virtual; |
1019 | 458 | _current.add_child (sym); | 551 | _current.add_child (sym); |
1020 | 459 | _current = sym; | 552 | _current = sym; |
1022 | 460 | s.accept_children (this); | 553 | |
1023 | 554 | foreach (Vala.Parameter param in s.get_parameters ()) { | ||
1024 | 555 | param.accept (this); | ||
1025 | 556 | } | ||
1026 | 557 | if (s.default_handler == null && s.body != null) { | ||
1027 | 558 | s.body.accept (this); | ||
1028 | 559 | } else if (s.default_handler != null) { | ||
1029 | 560 | s.default_handler.accept (this); | ||
1030 | 561 | } | ||
1031 | 562 | |||
1032 | 461 | _current = prev; | 563 | _current = prev; |
1033 | 462 | _current_sr = prev_sr; | 564 | _current_sr = prev_sr; |
1034 | 463 | _vala_symbol_fqn = prev_vala_fqn; | 565 | _vala_symbol_fqn = prev_vala_fqn; |
1035 | @@ -465,10 +567,9 @@ | |||
1036 | 465 | 567 | ||
1037 | 466 | public override void visit_field (Field f) | 568 | public override void visit_field (Field f) |
1038 | 467 | { | 569 | { |
1039 | 468 | _child_count++; | ||
1040 | 469 | var prev_vala_fqn = _vala_symbol_fqn; | 570 | var prev_vala_fqn = _vala_symbol_fqn; |
1041 | 470 | var prev = _current; | 571 | var prev = _current; |
1043 | 471 | var prev_sr = _current_sr; | 572 | unowned SourceReference prev_sr = _current_sr; |
1044 | 472 | 573 | ||
1045 | 473 | 574 | ||
1046 | 474 | set_fqn (f.name); | 575 | set_fqn (f.name); |
1047 | @@ -494,10 +595,9 @@ | |||
1048 | 494 | 595 | ||
1049 | 495 | public override void visit_constant (Vala.Constant c) | 596 | public override void visit_constant (Vala.Constant c) |
1050 | 496 | { | 597 | { |
1051 | 497 | _child_count++; | ||
1052 | 498 | var prev_vala_fqn = _vala_symbol_fqn; | 598 | var prev_vala_fqn = _vala_symbol_fqn; |
1053 | 499 | var prev = _current; | 599 | var prev = _current; |
1055 | 500 | var prev_sr = _current_sr; | 600 | unowned SourceReference prev_sr = _current_sr; |
1056 | 501 | 601 | ||
1057 | 502 | set_fqn (c.name); | 602 | set_fqn (c.name); |
1058 | 503 | var s = add_symbol (c, out _current_sr); | 603 | var s = add_symbol (c, out _current_sr); |
1059 | @@ -512,10 +612,9 @@ | |||
1060 | 512 | 612 | ||
1061 | 513 | public override void visit_property (Property p) | 613 | public override void visit_property (Property p) |
1062 | 514 | { | 614 | { |
1063 | 515 | _child_count++; | ||
1064 | 516 | var prev_vala_fqn = _vala_symbol_fqn; | 615 | var prev_vala_fqn = _vala_symbol_fqn; |
1065 | 517 | var prev = _current; | 616 | var prev = _current; |
1067 | 518 | var prev_sr = _current_sr; | 617 | unowned SourceReference prev_sr = _current_sr; |
1068 | 519 | 618 | ||
1069 | 520 | set_fqn (p.name); | 619 | set_fqn (p.name); |
1070 | 521 | var s = add_symbol (p, out _current_sr); | 620 | var s = add_symbol (p, out _current_sr); |
1071 | @@ -533,7 +632,17 @@ | |||
1072 | 533 | _current.add_child (s); | 632 | _current.add_child (s); |
1073 | 534 | 633 | ||
1074 | 535 | _current = s; | 634 | _current = s; |
1076 | 536 | p.accept_children (this); | 635 | if (p.get_accessor != null) { |
1077 | 636 | p.get_accessor.accept (this); | ||
1078 | 637 | } | ||
1079 | 638 | if (p.set_accessor != null) { | ||
1080 | 639 | p.set_accessor.accept (this); | ||
1081 | 640 | } | ||
1082 | 641 | |||
1083 | 642 | if (p.initializer != null) { | ||
1084 | 643 | p.initializer.accept (this); | ||
1085 | 644 | } | ||
1086 | 645 | |||
1087 | 537 | _current = prev; | 646 | _current = prev; |
1088 | 538 | _current_sr = prev_sr; | 647 | _current_sr = prev_sr; |
1089 | 539 | _vala_symbol_fqn = prev_vala_fqn; | 648 | _vala_symbol_fqn = prev_vala_fqn; |
1090 | @@ -544,7 +653,7 @@ | |||
1091 | 544 | this.visit_scoped_codenode (a.readable ? "get" : "set", a, a.body); | 653 | this.visit_scoped_codenode (a.readable ? "get" : "set", a, a.body); |
1092 | 545 | /* | 654 | /* |
1093 | 546 | var prev = _current; | 655 | var prev = _current; |
1095 | 547 | var prev_sr = _current_sr; | 656 | unowned SourceReference prev_sr = _current_sr; |
1096 | 548 | 657 | ||
1097 | 549 | if (a.body != null | 658 | if (a.body != null |
1098 | 550 | && a.body.source_reference != null | 659 | && a.body.source_reference != null |
1099 | @@ -559,17 +668,23 @@ | |||
1100 | 559 | 668 | ||
1101 | 560 | public override void visit_error_domain (ErrorDomain ed) | 669 | public override void visit_error_domain (ErrorDomain ed) |
1102 | 561 | { | 670 | { |
1103 | 562 | _child_count++; | ||
1104 | 563 | var prev_vala_fqn = _vala_symbol_fqn; | 671 | var prev_vala_fqn = _vala_symbol_fqn; |
1105 | 564 | var prev = _current; | 672 | var prev = _current; |
1107 | 565 | var prev_sr = _current_sr; | 673 | unowned SourceReference prev_sr = _current_sr; |
1108 | 566 | 674 | ||
1109 | 567 | set_fqn (ed.name); | 675 | set_fqn (ed.name); |
1110 | 568 | var s = add_symbol (ed, out _current_sr); | 676 | var s = add_symbol (ed, out _current_sr); |
1111 | 569 | _current.add_child (s); | 677 | _current.add_child (s); |
1112 | 570 | 678 | ||
1113 | 571 | _current = s; | 679 | _current = s; |
1115 | 572 | ed.accept_children (this); | 680 | |
1116 | 681 | foreach (ErrorCode ecode in ed.get_codes()) { | ||
1117 | 682 | ecode.accept (this); | ||
1118 | 683 | } | ||
1119 | 684 | foreach (Method m in ed.get_methods ()) { | ||
1120 | 685 | m.accept (this); | ||
1121 | 686 | } | ||
1122 | 687 | |||
1123 | 573 | 688 | ||
1124 | 574 | _current = prev; | 689 | _current = prev; |
1125 | 575 | _current_sr = prev_sr; | 690 | _current_sr = prev_sr; |
1126 | @@ -580,7 +695,7 @@ | |||
1127 | 580 | { | 695 | { |
1128 | 581 | var prev_vala_fqn = _vala_symbol_fqn; | 696 | var prev_vala_fqn = _vala_symbol_fqn; |
1129 | 582 | var prev = _current; | 697 | var prev = _current; |
1131 | 583 | var prev_sr = _current_sr; | 698 | unowned SourceReference prev_sr = _current_sr; |
1132 | 584 | 699 | ||
1133 | 585 | set_fqn (ecode.name); | 700 | set_fqn (ecode.name); |
1134 | 586 | var s = add_symbol (ecode, out _current_sr); | 701 | var s = add_symbol (ecode, out _current_sr); |
1135 | @@ -649,17 +764,14 @@ | |||
1136 | 649 | { | 764 | { |
1137 | 650 | var prev_vala_fqn = _vala_symbol_fqn; | 765 | var prev_vala_fqn = _vala_symbol_fqn; |
1138 | 651 | var prev = _current; | 766 | var prev = _current; |
1140 | 652 | 767 | ||
1141 | 653 | set_fqn (local.name); | 768 | set_fqn (local.name); |
1142 | 654 | DataType s = new DataType ("", local.name); | 769 | DataType s = new DataType ("", local.name); |
1143 | 655 | if (local.variable_type != null) { | 770 | if (local.variable_type != null) { |
1144 | 656 | s.type_name = get_datatype_typename (local.variable_type); | 771 | s.type_name = get_datatype_typename (local.variable_type); |
1149 | 657 | } else if (local.variable_type == null && local.initializer != null) { | 772 | } else if (local.variable_type == null) { |
1146 | 658 | // try to resolve local variable type from initializers | ||
1147 | 659 | var prev_inferred_type = _inferred_type; | ||
1148 | 660 | _inferred_type = s; | ||
1150 | 661 | //Utils.trace ("infer from init '%s': %s", s.name, local.initializer.type_name); | 773 | //Utils.trace ("infer from init '%s': %s", s.name, local.initializer.type_name); |
1152 | 662 | 774 | /* | |
1153 | 663 | if (local.initializer is ObjectCreationExpression) { | 775 | if (local.initializer is ObjectCreationExpression) { |
1154 | 664 | //debug ("START: initialization %s from %s: %s", local.name, s.name, _inferred_type.type_name); | 776 | //debug ("START: initialization %s from %s: %s", local.name, s.name, _inferred_type.type_name); |
1155 | 665 | var obj_initializer = (ObjectCreationExpression) local.initializer; | 777 | var obj_initializer = (ObjectCreationExpression) local.initializer; |
1156 | @@ -667,12 +779,22 @@ | |||
1157 | 667 | //debug ("END: initialization done %s", _inferred_type.type_name); | 779 | //debug ("END: initialization done %s", _inferred_type.type_name); |
1158 | 668 | } else if (local.initializer is MethodCall) { | 780 | } else if (local.initializer is MethodCall) { |
1159 | 669 | //Utils.trace ("method call: %s", s.name); | 781 | //Utils.trace ("method call: %s", s.name); |
1161 | 670 | ((MethodCall) local.initializer).call.accept (this); // this avoid visit parameters of method calls | 782 | var call = ((MethodCall) local.initializer); |
1162 | 783 | Utils.trace ("method call: %s -> %s %s", local.name, call.to_string (), call.call.type_name); | ||
1163 | 784 | var ma = call.call as MemberAccess; | ||
1164 | 785 | if (true || ma == null) | ||
1165 | 786 | call.call.accept (this); // this avoid visit parameters of method calls | ||
1166 | 787 | else { | ||
1167 | 788 | |||
1168 | 789 | Utils.trace ("ma inner: %s", ma.member_name); | ||
1169 | 790 | } | ||
1170 | 791 | Utils.trace ("AFTER: %s", s.type_name); | ||
1171 | 792 | //breakpoint(); | ||
1172 | 671 | } else if (local.initializer is BinaryExpression) { | 793 | } else if (local.initializer is BinaryExpression) { |
1173 | 672 | ((BinaryExpression) local.initializer).accept_children (this); | 794 | ((BinaryExpression) local.initializer).accept_children (this); |
1174 | 673 | } else if (local.initializer is CastExpression) { | 795 | } else if (local.initializer is CastExpression) { |
1175 | 674 | var cast_expr = (CastExpression)local.initializer; | 796 | var cast_expr = (CastExpression)local.initializer; |
1177 | 675 | cast_expr.accept (this); | 797 | //cast_expr.accept (this); |
1178 | 676 | if (cast_expr.type_reference != null) | 798 | if (cast_expr.type_reference != null) |
1179 | 677 | { | 799 | { |
1180 | 678 | s.type_name = get_datatype_typename (cast_expr.type_reference); | 800 | s.type_name = get_datatype_typename (cast_expr.type_reference); |
1181 | @@ -680,13 +802,34 @@ | |||
1182 | 680 | } else if (local.initializer is ArrayCreationExpression) { | 802 | } else if (local.initializer is ArrayCreationExpression) { |
1183 | 681 | //Utils.trace ("ArrayCreationExpression infer from init '%s' %s", s.name, local.initializer.type_name); | 803 | //Utils.trace ("ArrayCreationExpression infer from init '%s' %s", s.name, local.initializer.type_name); |
1184 | 682 | var ac = (ArrayCreationExpression) local.initializer; | 804 | var ac = (ArrayCreationExpression) local.initializer; |
1185 | 683 | ac.accept_children (this); | ||
1186 | 684 | s.is_array = true; | 805 | s.is_array = true; |
1187 | 806 | if (ac.element_type == null) { | ||
1188 | 807 | if (ac.initializer_list != null) { | ||
1189 | 808 | ac.initializer_list.accept (this); | ||
1190 | 809 | } | ||
1191 | 810 | } | ||
1192 | 685 | s.type_name = get_datatype_typename (ac.element_type); | 811 | s.type_name = get_datatype_typename (ac.element_type); |
1193 | 686 | //Utils.trace ("init type %s: %s %s", local.name, s.type_name, ac.element_type.type_name); | 812 | //Utils.trace ("init type %s: %s %s", local.name, s.type_name, ac.element_type.type_name); |
1194 | 687 | } else { | 813 | } else { |
1197 | 688 | local.accept_children (this); | 814 | if (local.initializer != null) { |
1198 | 689 | } | 815 | local.initializer.accept (this); |
1199 | 816 | } | ||
1200 | 817 | } | ||
1201 | 818 | */ | ||
1202 | 819 | // try to resolve local variable type from initializers | ||
1203 | 820 | var prev_inferred_type = _inferred_type; | ||
1204 | 821 | _inferred_type = s; | ||
1205 | 822 | |||
1206 | 823 | if (local.initializer != null) { | ||
1207 | 824 | local.initializer.accept (this); | ||
1208 | 825 | // HACK: | ||
1209 | 826 | if (s.type_name != null | ||
1210 | 827 | && (s.type_name.has_prefix ("this.") || s.type_name.has_prefix ("base."))) | ||
1211 | 828 | { | ||
1212 | 829 | s.type_name = s.type_name.substring (5); | ||
1213 | 830 | } | ||
1214 | 831 | } | ||
1215 | 832 | |||
1216 | 690 | _last_literal = null; | 833 | _last_literal = null; |
1217 | 691 | //debug ("infer from init done %s", _inferred_type.type_name); | 834 | //debug ("infer from init done %s", _inferred_type.type_name); |
1218 | 692 | _inferred_type = prev_inferred_type; | 835 | _inferred_type = prev_inferred_type; |
1219 | @@ -734,23 +877,34 @@ | |||
1220 | 734 | { | 877 | { |
1221 | 735 | if (_inferred_type == null) | 878 | if (_inferred_type == null) |
1222 | 736 | return; | 879 | return; |
1230 | 737 | 880 | ||
1231 | 738 | //Utils.trace ("visit member access %s: %s", _inferred_type.type_name, expr.member_name); | 881 | string member_name = expr.member_name; |
1232 | 739 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") | 882 | //Utils.trace ("MemberAccess %s: %s", _current.name, expr.member_name); |
1233 | 740 | _inferred_type.type_name = expr.member_name; | 883 | if (expr.inner == null) { |
1234 | 741 | else { | 884 | // this is the last iteration |
1235 | 742 | string member_name = null; | 885 | // lookup the name in all the visible symbols |
1229 | 743 | // lookup in the scope variables | ||
1236 | 744 | if (_current != null) { | 886 | if (_current != null) { |
1238 | 745 | DataType d = _current.scope_lookup_datatype_for_variable (CompareMode.EXACT, expr.member_name); | 887 | // try the first optimized path |
1239 | 888 | DataType d = _current.lookup_datatype_for_variable_name (CompareMode.EXACT, member_name); | ||
1240 | 746 | if (d != null) { | 889 | if (d != null) { |
1241 | 747 | member_name = d.type_name; | 890 | member_name = d.type_name; |
1242 | 891 | } else if (_current.parent != null) { | ||
1243 | 892 | d = _current.parent.lookup_datatype_for_symbol_name (CompareMode.EXACT, member_name); | ||
1244 | 893 | if (d != null) { | ||
1245 | 894 | member_name = d.type_name; | ||
1246 | 895 | } /* else { | ||
1247 | 896 | // this is the slowest path | ||
1248 | 897 | d = _current.scope_lookup_datatype_for_name (CompareMode.EXACT, member_name); | ||
1249 | 898 | if (d != null) { | ||
1250 | 899 | member_name = d.type_name; | ||
1251 | 900 | } | ||
1252 | 901 | }*/ | ||
1253 | 748 | } | 902 | } |
1254 | 749 | } | 903 | } |
1259 | 750 | 904 | } | |
1260 | 751 | // if not found assume that is a static type | 905 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") { |
1261 | 752 | if (member_name == null) | 906 | _inferred_type.type_name = member_name; |
1262 | 753 | member_name = expr.member_name; | 907 | } else { |
1263 | 754 | _inferred_type.type_name = "%s.%s".printf (member_name, _inferred_type.type_name); | 908 | _inferred_type.type_name = "%s.%s".printf (member_name, _inferred_type.type_name); |
1264 | 755 | } | 909 | } |
1265 | 756 | } | 910 | } |
1266 | @@ -777,7 +931,6 @@ | |||
1267 | 777 | 931 | ||
1268 | 778 | public override void visit_binary_expression (BinaryExpression expr) | 932 | public override void visit_binary_expression (BinaryExpression expr) |
1269 | 779 | { | 933 | { |
1270 | 780 | //debug ("vidit binary expr %p", expr); | ||
1271 | 781 | expr.accept_children (this); | 934 | expr.accept_children (this); |
1272 | 782 | } | 935 | } |
1273 | 783 | 936 | ||
1274 | @@ -788,8 +941,6 @@ | |||
1275 | 788 | 941 | ||
1276 | 789 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") | 942 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") |
1277 | 790 | _inferred_type.type_name = "bool"; | 943 | _inferred_type.type_name = "bool"; |
1278 | 791 | else if (_inferred_type.type_name != "bool") | ||
1279 | 792 | _inferred_type.type_name = "%s.%s".printf ("bool", _inferred_type.type_name); | ||
1280 | 793 | } | 944 | } |
1281 | 794 | 945 | ||
1282 | 795 | 946 | ||
1283 | @@ -800,8 +951,6 @@ | |||
1284 | 800 | 951 | ||
1285 | 801 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") | 952 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") |
1286 | 802 | _inferred_type.type_name = "char"; | 953 | _inferred_type.type_name = "char"; |
1287 | 803 | else if (_inferred_type.type_name != "char") | ||
1288 | 804 | _inferred_type.type_name = "%s.%s".printf ("char", _inferred_type.type_name); | ||
1289 | 805 | } | 954 | } |
1290 | 806 | 955 | ||
1291 | 807 | public override void visit_integer_literal (IntegerLiteral lit) | 956 | public override void visit_integer_literal (IntegerLiteral lit) |
1292 | @@ -811,8 +960,6 @@ | |||
1293 | 811 | 960 | ||
1294 | 812 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") | 961 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") |
1295 | 813 | _inferred_type.type_name = lit.type_name; | 962 | _inferred_type.type_name = lit.type_name; |
1296 | 814 | else if (_inferred_type.type_name != lit.type_name) | ||
1297 | 815 | _inferred_type.type_name = "%s.%s".printf (lit.type_name, _inferred_type.type_name); | ||
1298 | 816 | } | 963 | } |
1299 | 817 | 964 | ||
1300 | 818 | public override void visit_real_literal (RealLiteral lit) | 965 | public override void visit_real_literal (RealLiteral lit) |
1301 | @@ -821,8 +968,6 @@ | |||
1302 | 821 | return; | 968 | return; |
1303 | 822 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") | 969 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") |
1304 | 823 | _inferred_type.type_name = lit.get_type_name (); | 970 | _inferred_type.type_name = lit.get_type_name (); |
1305 | 824 | else if (_inferred_type.type_name != lit.get_type_name ()) | ||
1306 | 825 | _inferred_type.type_name = "%s.%s".printf (lit.get_type_name (), _inferred_type.type_name); | ||
1307 | 826 | } | 971 | } |
1308 | 827 | 972 | ||
1309 | 828 | public override void visit_string_literal (StringLiteral lit) | 973 | public override void visit_string_literal (StringLiteral lit) |
1310 | @@ -832,8 +977,6 @@ | |||
1311 | 832 | 977 | ||
1312 | 833 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") | 978 | if (_inferred_type.type_name == null || _inferred_type.type_name == "") |
1313 | 834 | _inferred_type.type_name = "string"; | 979 | _inferred_type.type_name = "string"; |
1314 | 835 | else if (_inferred_type.type_name != "string") | ||
1315 | 836 | _inferred_type.type_name = "%s.%s".printf ("string", _inferred_type.type_name); | ||
1316 | 837 | } | 980 | } |
1317 | 838 | 981 | ||
1318 | 839 | public override void visit_declaration_statement (DeclarationStatement stmt) | 982 | public override void visit_declaration_statement (DeclarationStatement stmt) |
1319 | @@ -885,7 +1028,7 @@ | |||
1320 | 885 | { | 1028 | { |
1321 | 886 | var s = visit_scoped_codenode ("catch", clause, clause.body); | 1029 | var s = visit_scoped_codenode ("catch", clause, clause.body); |
1322 | 887 | var d = new DataType (get_datatype_typename (clause.error_type), clause.variable_name); | 1030 | var d = new DataType (get_datatype_typename (clause.error_type), clause.variable_name); |
1324 | 888 | s.add_local_variable (d); | 1031 | s.add_local_variable (d); |
1325 | 889 | } | 1032 | } |
1326 | 890 | 1033 | ||
1327 | 891 | public override void visit_if_statement (IfStatement stmt) | 1034 | public override void visit_if_statement (IfStatement stmt) |
1328 | @@ -965,7 +1108,7 @@ | |||
1329 | 965 | { | 1108 | { |
1330 | 966 | var prev_vala_fqn = _vala_symbol_fqn; | 1109 | var prev_vala_fqn = _vala_symbol_fqn; |
1331 | 967 | var prev = _current; | 1110 | var prev = _current; |
1333 | 968 | var prev_sr = _current_sr; | 1111 | unowned SourceReference prev_sr = _current_sr; |
1334 | 969 | 1112 | ||
1335 | 970 | set_fqn ("!%s".printf (name)); | 1113 | set_fqn ("!%s".printf (name)); |
1336 | 971 | int last_line = 0; | 1114 | int last_line = 0; |
1337 | 972 | 1115 | ||
1338 | === modified file 'plugins/completion/afrodite-provider/afrodite/completionengine.vala' | |||
1339 | --- plugins/completion/afrodite-provider/afrodite/completionengine.vala 2010-12-30 07:38:50 +0000 | |||
1340 | +++ plugins/completion/afrodite-provider/afrodite/completionengine.vala 2011-03-10 19:26:24 +0000 | |||
1341 | @@ -37,16 +37,16 @@ | |||
1342 | 37 | 37 | ||
1343 | 38 | private Mutex _source_queue_mutex; | 38 | private Mutex _source_queue_mutex; |
1344 | 39 | private Mutex _merge_queue_mutex; | 39 | private Mutex _merge_queue_mutex; |
1345 | 40 | private Mutex _ast_mutex = null; | ||
1346 | 41 | 40 | ||
1347 | 42 | private unowned Thread<int> _parser_thread; | 41 | private unowned Thread<int> _parser_thread; |
1348 | 43 | private int _parser_stamp = 0; | 42 | private int _parser_stamp = 0; |
1349 | 44 | private int _parser_remaining_files = 0; | 43 | private int _parser_remaining_files = 0; |
1350 | 45 | private int _current_parsing_total_file_count = 0; | 44 | private int _current_parsing_total_file_count = 0; |
1351 | 46 | private bool _glib_init = false; | 45 | private bool _glib_init = false; |
1353 | 47 | 46 | private bool _is_parsing = false; | |
1354 | 47 | |||
1355 | 48 | private Ast _ast; | 48 | private Ast _ast; |
1357 | 49 | private Vala.HashMap<string, ParseResult> _parse_result_list = new Vala.HashMap<string, ParseResult> (GLib.str_hash, GLib.str_equal, GLib.direct_equal); | 49 | private Vala.List<ParseResult> _parse_result_list = new Vala.ArrayList<ParseResult> (); |
1358 | 50 | private uint _idle_id = 0; | 50 | private uint _idle_id = 0; |
1359 | 51 | 51 | ||
1360 | 52 | public CompletionEngine (string? id = null) | 52 | public CompletionEngine (string? id = null) |
1361 | @@ -62,16 +62,13 @@ | |||
1362 | 62 | _merge_queue_mutex = new Mutex (); | 62 | _merge_queue_mutex = new Mutex (); |
1363 | 63 | 63 | ||
1364 | 64 | _ast = new Ast (); | 64 | _ast = new Ast (); |
1365 | 65 | _ast_mutex = new Mutex (); | ||
1366 | 66 | } | 65 | } |
1367 | 67 | 66 | ||
1368 | 68 | ~Completion () | 67 | ~Completion () |
1369 | 69 | { | 68 | { |
1370 | 70 | Utils.trace ("Completion %s destroy", id); | 69 | Utils.trace ("Completion %s destroy", id); |
1371 | 71 | // invalidate the ast so the parser thread will exit asap | 70 | // invalidate the ast so the parser thread will exit asap |
1372 | 72 | _ast_mutex.lock (); | ||
1373 | 73 | _ast = null; | 71 | _ast = null; |
1374 | 74 | _ast_mutex.unlock (); | ||
1375 | 75 | 72 | ||
1376 | 76 | if (AtomicInt.@get (ref _parser_stamp) != 0) { | 73 | if (AtomicInt.@get (ref _parser_stamp) != 0) { |
1377 | 77 | Utils.trace ("join the parser thread before exit"); | 74 | Utils.trace ("join the parser thread before exit"); |
1378 | @@ -88,7 +85,7 @@ | |||
1379 | 88 | public bool is_parsing | 85 | public bool is_parsing |
1380 | 89 | { | 86 | { |
1381 | 90 | get { | 87 | get { |
1383 | 91 | return AtomicInt.@get (ref _parser_stamp) != 0; | 88 | return _is_parsing; |
1384 | 92 | } | 89 | } |
1385 | 93 | } | 90 | } |
1386 | 94 | 91 | ||
1387 | @@ -121,8 +118,10 @@ | |||
1388 | 121 | return null; | 118 | return null; |
1389 | 122 | } | 119 | } |
1390 | 123 | 120 | ||
1392 | 124 | public void queue_sources (Vala.List<SourceItem> sources) | 121 | public bool queue_sources (Vala.List<SourceItem> sources, bool no_update_check = false) |
1393 | 125 | { | 122 | { |
1394 | 123 | bool result = false; | ||
1395 | 124 | |||
1396 | 126 | _source_queue_mutex.@lock (); | 125 | _source_queue_mutex.@lock (); |
1397 | 127 | if (!_glib_init) { | 126 | if (!_glib_init) { |
1398 | 128 | // merge standard base vapi (glib and gobject) | 127 | // merge standard base vapi (glib and gobject) |
1399 | @@ -144,22 +143,36 @@ | |||
1400 | 144 | } | 143 | } |
1401 | 145 | } | 144 | } |
1402 | 146 | foreach (SourceItem source in sources) { | 145 | foreach (SourceItem source in sources) { |
1419 | 147 | var item = source_queue_contains (source); | 146 | bool skip_unchanged_file = false; |
1420 | 148 | if (item == null || item.content != source.content) { | 147 | |
1421 | 149 | /* | 148 | // test if file is really changed but only if it's not a live buffer |
1422 | 150 | if (source.content == null || source.content == "") | 149 | if (no_update_check == false && source.content == null && _ast != null) { |
1423 | 151 | Utils.trace ("%s: queued source %s. sources to parse %d", id, source.path, source_queue.size); | 150 | var sf = _ast.lookup_source_file (source.path); |
1424 | 152 | else | 151 | if (sf != null && sf.update_last_modification_time ()) { |
1425 | 153 | Utils.trace ("%s: queued live buffer %s. sources to parse %d", id, source.path, source_queue.size); | 152 | Utils.trace ("engine %s: skip unchanged source %s", id, source.path); |
1426 | 154 | */ | 153 | skip_unchanged_file = true; |
1427 | 155 | if (item != null) | 154 | } |
1428 | 156 | _source_queue.remove (item); | 155 | } |
1429 | 157 | 156 | ||
1430 | 158 | _source_queue.add (source.copy ()); | 157 | if (!skip_unchanged_file) |
1431 | 159 | } | 158 | { |
1432 | 160 | else if (item.content == null && source.content != null) { | 159 | var item = source_queue_contains (source); |
1433 | 161 | item.content = source.content; | 160 | if (item == null || item.content != source.content) { |
1434 | 162 | //Utils.trace ("%s: updated live buffer %s. sources to parse %d", id, source.path, source_queue.size); | 161 | /* |
1435 | 162 | if (source.content == null || source.content == "") | ||
1436 | 163 | Utils.trace ("%s: queued source %s. sources to parse %d", id, source.path, source_queue.size); | ||
1437 | 164 | else | ||
1438 | 165 | Utils.trace ("%s: queued live buffer %s. sources to parse %d", id, source.path, source_queue.size); | ||
1439 | 166 | */ | ||
1440 | 167 | if (item != null) | ||
1441 | 168 | _source_queue.remove (item); | ||
1442 | 169 | |||
1443 | 170 | _source_queue.add (source.copy ()); | ||
1444 | 171 | } | ||
1445 | 172 | else if (item.content == null && source.content != null) { | ||
1446 | 173 | item.content = source.content; | ||
1447 | 174 | //Utils.trace ("%s: updated live buffer %s. sources to parse %d", id, source.path, source_queue.size); | ||
1448 | 175 | } | ||
1449 | 163 | } | 176 | } |
1450 | 164 | } | 177 | } |
1451 | 165 | _source_queue_mutex.@unlock (); | 178 | _source_queue_mutex.@unlock (); |
1452 | @@ -168,7 +181,9 @@ | |||
1453 | 168 | create_parser_thread (); | 181 | create_parser_thread (); |
1454 | 169 | } else { | 182 | } else { |
1455 | 170 | AtomicInt.inc (ref _parser_stamp); | 183 | AtomicInt.inc (ref _parser_stamp); |
1457 | 171 | } | 184 | } |
1458 | 185 | |||
1459 | 186 | return result; | ||
1460 | 172 | } | 187 | } |
1461 | 173 | 188 | ||
1462 | 174 | public void queue_sourcefile (string path, string? content = null, bool is_vapi = false, bool is_glib = false) | 189 | public void queue_sourcefile (string path, string? content = null, bool is_vapi = false, bool is_glib = false) |
1463 | @@ -193,52 +208,12 @@ | |||
1464 | 193 | 208 | ||
1465 | 194 | queue_sources (sources); | 209 | queue_sources (sources); |
1466 | 195 | } | 210 | } |
1513 | 196 | 211 | ||
1514 | 197 | public bool try_acquire_ast (out Ast ast, int retry_count = -1) | 212 | public Ast ast |
1515 | 198 | { | 213 | { |
1516 | 199 | bool res = false; | 214 | get { |
1517 | 200 | ast = null; | 215 | return _ast; |
1518 | 201 | bool first_run = true; | 216 | } |
1473 | 202 | int file_count = 0; | ||
1474 | 203 | int retry = 0; | ||
1475 | 204 | |||
1476 | 205 | while (ast == null | ||
1477 | 206 | && _ast_mutex != null | ||
1478 | 207 | && (first_run || (file_count = AtomicInt.get (ref _current_parsing_total_file_count)) <= 2)) | ||
1479 | 208 | { | ||
1480 | 209 | first_run = false; | ||
1481 | 210 | res = _ast_mutex.@trylock (); | ||
1482 | 211 | if (res) { | ||
1483 | 212 | ast = _ast; | ||
1484 | 213 | } else { | ||
1485 | 214 | if (retry_count < 0 || retry < retry_count) { | ||
1486 | 215 | retry++; | ||
1487 | 216 | GLib.Thread.usleep (100 * 1000); | ||
1488 | 217 | } else { | ||
1489 | 218 | break; | ||
1490 | 219 | } | ||
1491 | 220 | } | ||
1492 | 221 | } | ||
1493 | 222 | |||
1494 | 223 | #if DEBUG | ||
1495 | 224 | if (ast == null) { | ||
1496 | 225 | //Utils.trace ("can't acquire lock: %d", file_count); | ||
1497 | 226 | } else { | ||
1498 | 227 | Utils.trace ("lock acquired: %d", file_count); | ||
1499 | 228 | } | ||
1500 | 229 | #endif | ||
1501 | 230 | |||
1502 | 231 | return res; | ||
1503 | 232 | } | ||
1504 | 233 | |||
1505 | 234 | public void release_ast (Ast ast) | ||
1506 | 235 | { | ||
1507 | 236 | if (_ast != ast) { | ||
1508 | 237 | warning ("%s: release_ast requested for unknown ast instance", id); | ||
1509 | 238 | return; | ||
1510 | 239 | } | ||
1511 | 240 | |||
1512 | 241 | _ast_mutex.unlock (); | ||
1519 | 242 | } | 217 | } |
1520 | 243 | 218 | ||
1521 | 244 | private void create_parser_thread () | 219 | private void create_parser_thread () |
1522 | @@ -257,26 +232,19 @@ | |||
1523 | 257 | { | 232 | { |
1524 | 258 | #if DEBUG | 233 | #if DEBUG |
1525 | 259 | GLib.Timer timer = new GLib.Timer (); | 234 | GLib.Timer timer = new GLib.Timer (); |
1526 | 260 | double start_parsing_time = 0; | ||
1527 | 261 | double parsing_time = 0; | ||
1528 | 262 | double start_time = 0; | 235 | double start_time = 0; |
1529 | 263 | timer.start (); | 236 | timer.start (); |
1530 | 264 | #endif | 237 | #endif |
1531 | 265 | Utils.trace ("engine %s: parser thread *** starting ***...", id); | 238 | Utils.trace ("engine %s: parser thread *** starting ***...", id); |
1533 | 266 | begin_parsing (this); | 239 | |
1534 | 267 | Vala.List<SourceItem> sources = new ArrayList<SourceItem> (); | 240 | Vala.List<SourceItem> sources = new ArrayList<SourceItem> (); |
1535 | 268 | 241 | ||
1536 | 269 | while (true) { | 242 | while (true) { |
1537 | 270 | #if DEBUG | ||
1538 | 271 | start_parsing_time = timer.elapsed (); | ||
1539 | 272 | #endif | ||
1540 | 273 | int stamp = AtomicInt.get (ref _parser_stamp); | 243 | int stamp = AtomicInt.get (ref _parser_stamp); |
1544 | 274 | // set the number of sources to process + 1, because the last one | 244 | // set the number of sources to process |
1545 | 275 | // will be decreased by the resolve part | 245 | AtomicInt.set (ref _parser_remaining_files, _source_queue.size ); |
1543 | 276 | AtomicInt.set (ref _parser_remaining_files, _source_queue.size + 1); | ||
1546 | 277 | // get the source to parse | 246 | // get the source to parse |
1547 | 278 | _source_queue_mutex.@lock (); | 247 | _source_queue_mutex.@lock (); |
1548 | 279 | int source_count = _source_queue.size; | ||
1549 | 280 | foreach (SourceItem item in _source_queue) { | 248 | foreach (SourceItem item in _source_queue) { |
1550 | 281 | sources.add (item.copy ()); | 249 | sources.add (item.copy ()); |
1551 | 282 | } | 250 | } |
1552 | @@ -287,109 +255,28 @@ | |||
1553 | 287 | _source_queue.clear (); | 255 | _source_queue.clear (); |
1554 | 288 | _source_queue_mutex.@unlock (); | 256 | _source_queue_mutex.@unlock (); |
1555 | 289 | 257 | ||
1556 | 290 | AstMerger merger = null; | ||
1557 | 291 | foreach (SourceItem source in sources) { | 258 | foreach (SourceItem source in sources) { |
1635 | 292 | bool skip_unchanged_file = false; | 259 | #if DEBUG |
1636 | 293 | 260 | Utils.trace ("engine %s: parsing source: %s", id, source.path); | |
1637 | 294 | // test if file is really changed but only if it's not a live buffer | 261 | start_time = timer.elapsed (); |
1638 | 295 | if (source.content == null) { | 262 | #endif |
1639 | 296 | _ast_mutex.@lock (); | 263 | |
1640 | 297 | if (_ast != null) { | 264 | Parser p = new Parser.with_source (source); |
1641 | 298 | var sf = _ast.lookup_source_file (source.path); | 265 | var parse_results = p.parse (); |
1642 | 299 | if (sf != null) { | 266 | lock (_parse_result_list) { |
1643 | 300 | if (sf.update_last_modification_time ()) { | 267 | _parse_result_list.add (parse_results); |
1644 | 301 | // no need to reparse the source since it isn't changed | 268 | if (_idle_id == 0) |
1645 | 302 | Utils.trace ("engine %s: source file parsing optimized out since it isn't changed: %s", id, source.path); | 269 | //_idle_id = Idle.add (this.on_parse_results, Priority.LOW); |
1646 | 303 | _ast_mutex.@unlock (); | 270 | _idle_id = Timeout.add (250, this.on_parse_results, Priority.LOW); |
1647 | 304 | skip_unchanged_file = true; | 271 | } |
1648 | 305 | } | 272 | #if DEBUG |
1649 | 306 | } | 273 | Utils.trace ("engine %s: parsing source: %s done %g", id, source.path, timer.elapsed () - start_time); |
1650 | 307 | } | 274 | #endif |
1574 | 308 | _ast_mutex.@unlock (); | ||
1575 | 309 | } | ||
1576 | 310 | |||
1577 | 311 | if (!skip_unchanged_file) { | ||
1578 | 312 | #if DEBUG | ||
1579 | 313 | Utils.trace ("engine %s: parsing source: %s", id, source.path); | ||
1580 | 314 | start_time = timer.elapsed (); | ||
1581 | 315 | #endif | ||
1582 | 316 | |||
1583 | 317 | Parser p = new Parser.with_source (source); | ||
1584 | 318 | var parse_results = p.parse (); | ||
1585 | 319 | lock (_parse_result_list) { | ||
1586 | 320 | _parse_result_list.set (source.path, parse_results); | ||
1587 | 321 | if (_idle_id == 0) | ||
1588 | 322 | _idle_id = Idle.add_full (Priority.LOW, on_parse_results); | ||
1589 | 323 | } | ||
1590 | 324 | #if DEBUG | ||
1591 | 325 | Utils.trace ("engine %s: parsing source: %s done %g", id, source.path, timer.elapsed () - start_time); | ||
1592 | 326 | #endif | ||
1593 | 327 | source.context = p.context; | ||
1594 | 328 | if (source.context == null) | ||
1595 | 329 | critical ("source %s context == null, non thread safe access to source item", source.path); | ||
1596 | 330 | else { | ||
1597 | 331 | foreach (Vala.SourceFile s in source.context.get_source_files ()) { | ||
1598 | 332 | if (s.filename == source.path) { | ||
1599 | 333 | // do the real merge | ||
1600 | 334 | _ast_mutex.@lock (); | ||
1601 | 335 | if (_ast != null) { | ||
1602 | 336 | bool source_exists = _ast.lookup_source_file (source.path) != null; | ||
1603 | 337 | |||
1604 | 338 | // if the ast is still valid: not null | ||
1605 | 339 | // and not | ||
1606 | 340 | // if I'm parsing just one source and there are errors and the source already exists in the ast: I'll keep the previous copy | ||
1607 | 341 | // do the merge | ||
1608 | 342 | if (!(source_count == 1 && source_exists && p.context.report.get_errors () > 0)) { | ||
1609 | 343 | if (merger == null) { | ||
1610 | 344 | // lazy init the merger, here I'm sure that _ast != null | ||
1611 | 345 | merger = new AstMerger (_ast); | ||
1612 | 346 | } | ||
1613 | 347 | if (source_exists) { | ||
1614 | 348 | merger.remove_source_filename (source.path); | ||
1615 | 349 | } | ||
1616 | 350 | #if DEBUG | ||
1617 | 351 | Utils.trace ("engine %s: merging source %s", id, source.path); | ||
1618 | 352 | start_time = timer.elapsed (); | ||
1619 | 353 | #endif | ||
1620 | 354 | merger.merge_vala_context (s, source.context, source.is_glib); | ||
1621 | 355 | #if DEBUG | ||
1622 | 356 | Utils.trace ("engine %s: merging source %s done %g", id, source.path, timer.elapsed () - start_time); | ||
1623 | 357 | #endif | ||
1624 | 358 | } | ||
1625 | 359 | } | ||
1626 | 360 | _ast_mutex.unlock (); | ||
1627 | 361 | |||
1628 | 362 | //timer.stop (); | ||
1629 | 363 | //debug ("%s: merging context and file %s in %g", id, s.filename, timer.elapsed ()); | ||
1630 | 364 | break; | ||
1631 | 365 | } | ||
1632 | 366 | } | ||
1633 | 367 | } | ||
1634 | 368 | } | ||
1651 | 369 | AtomicInt.add (ref _parser_remaining_files, -1); | 275 | AtomicInt.add (ref _parser_remaining_files, -1); |
1652 | 370 | } | 276 | } |
1653 | 371 | #if DEBUG | ||
1654 | 372 | parsing_time += (timer.elapsed () - start_parsing_time); | ||
1655 | 373 | #endif | ||
1656 | 374 | 277 | ||
1657 | 375 | _ast_mutex.@lock (); | ||
1658 | 376 | if (_ast != null) { | ||
1659 | 377 | #if DEBUG | ||
1660 | 378 | //_ast.dump_symbols (); | ||
1661 | 379 | Utils.trace ("engine %s: resolving ast", id); | ||
1662 | 380 | start_time = timer.elapsed (); | ||
1663 | 381 | #endif | ||
1664 | 382 | var resolver = new SymbolResolver (); | ||
1665 | 383 | resolver.resolve (_ast); | ||
1666 | 384 | #if DEBUG | ||
1667 | 385 | Utils.trace ("engine %s: resolving ast done %g", id, timer.elapsed () - start_time); | ||
1668 | 386 | #endif | ||
1669 | 387 | } | ||
1670 | 388 | AtomicInt.add (ref _parser_remaining_files, -1); | ||
1671 | 389 | _ast_mutex.unlock (); | ||
1672 | 390 | |||
1673 | 391 | sources.clear (); | 278 | sources.clear (); |
1675 | 392 | 279 | ||
1676 | 393 | //check for changes or exit request | 280 | //check for changes or exit request |
1677 | 394 | if (_ast == null || AtomicInt.compare_and_exchange (ref _parser_stamp, stamp, 0)) { | 281 | if (_ast == null || AtomicInt.compare_and_exchange (ref _parser_stamp, stamp, 0)) { |
1678 | 395 | break; | 282 | break; |
1679 | @@ -402,36 +289,152 @@ | |||
1680 | 402 | 289 | ||
1681 | 403 | #if DEBUG | 290 | #if DEBUG |
1682 | 404 | timer.stop (); | 291 | timer.stop (); |
1684 | 405 | Utils.trace ("engine %s: parser thread *** exiting *** (elapsed time parsing %g, resolving %g)...", id, parsing_time, timer.elapsed ()); | 292 | Utils.trace ("engine %s: parser thread *** exiting *** (elapsed time parsing %g)...", id, timer.elapsed()); |
1685 | 406 | #endif | 293 | #endif |
1686 | 407 | end_parsing (this); | ||
1687 | 408 | return 0; | 294 | return 0; |
1688 | 409 | } | 295 | } |
1690 | 410 | 296 | ||
1691 | 297 | private void on_begin_parsing () | ||
1692 | 298 | { | ||
1693 | 299 | if (!_is_parsing) { | ||
1694 | 300 | _is_parsing = true; | ||
1695 | 301 | begin_parsing (this); | ||
1696 | 302 | } | ||
1697 | 303 | } | ||
1698 | 304 | |||
1699 | 305 | private void on_end_parsing () | ||
1700 | 306 | { | ||
1701 | 307 | if (AtomicInt.@get (ref _current_parsing_total_file_count) == 0) { | ||
1702 | 308 | _is_parsing = false; | ||
1703 | 309 | end_parsing (this); | ||
1704 | 310 | } | ||
1705 | 311 | } | ||
1706 | 312 | |||
1707 | 313 | |||
1708 | 411 | private bool on_parse_results () | 314 | private bool on_parse_results () |
1709 | 412 | { | 315 | { |
1713 | 413 | bool more_results = true; | 316 | bool merge_scheduled = false; |
1711 | 414 | string filename = null; | ||
1712 | 415 | ParseResult result = null; | ||
1714 | 416 | 317 | ||
1715 | 417 | lock (_parse_result_list) { | 318 | lock (_parse_result_list) { |
1716 | 418 | if (_parse_result_list.size > 0) { | 319 | if (_parse_result_list.size > 0) { |
1722 | 419 | foreach (string key in _parse_result_list.get_keys ()) { | 320 | foreach (ParseResult key in _parse_result_list) { |
1723 | 420 | result = _parse_result_list.get (key); | 321 | if (!merge_scheduled) { |
1724 | 421 | _parse_result_list.remove (key); | 322 | merge_scheduled = true; |
1725 | 422 | filename = key; | 323 | merge_and_resolve.begin (key, this.on_merge_and_resolve_ended); |
1726 | 423 | break; // one iteration | 324 | _parse_result_list.remove (key); |
1727 | 325 | break; | ||
1728 | 326 | } | ||
1729 | 424 | } | 327 | } |
1732 | 425 | } | 328 | } else { |
1733 | 426 | if (_parse_result_list.size == 0) { | 329 | // Tell to the parser thread the a new Idle should be created |
1734 | 330 | // for the merge process | ||
1735 | 427 | _idle_id = 0; | 331 | _idle_id = 0; |
1743 | 428 | more_results = false; | 332 | } |
1744 | 429 | } | 333 | } |
1745 | 430 | } | 334 | |
1746 | 431 | if (result != null) { | 335 | if (merge_scheduled) { |
1747 | 432 | this.file_parsed (this, filename, result); | 336 | on_begin_parsing(); |
1748 | 433 | } | 337 | } else { |
1749 | 434 | return more_results; | 338 | // this is the last run after the merge |
1750 | 339 | on_end_parsing (); | ||
1751 | 340 | } | ||
1752 | 341 | |||
1753 | 342 | return false; | ||
1754 | 343 | } | ||
1755 | 344 | |||
1756 | 345 | private void on_merge_and_resolve_ended (GLib.Object? source, GLib.AsyncResult r) | ||
1757 | 346 | { | ||
1758 | 347 | merge_and_resolve.end (r); | ||
1759 | 348 | //_idle_id = Idle.add (this.on_parse_results, Priority.LOW); | ||
1760 | 349 | _idle_id = Timeout.add (250, this.on_parse_results, Priority.LOW); | ||
1761 | 350 | } | ||
1762 | 351 | |||
1763 | 352 | private async ParseResult merge_and_resolve (ParseResult result) | ||
1764 | 353 | { | ||
1765 | 354 | Utils.trace ("engine %s: async merge and resolve: %s", id, result.source_path); | ||
1766 | 355 | foreach (Vala.SourceFile s in result.context.get_source_files ()) { | ||
1767 | 356 | if (s.filename == result.source_path) { | ||
1768 | 357 | var ast_source = _ast.lookup_source_file (result.source_path); | ||
1769 | 358 | bool source_exists = ast_source != null; | ||
1770 | 359 | bool need_update = true; | ||
1771 | 360 | |||
1772 | 361 | // if I already parsed this source and this copy is a live gedit buffer | ||
1773 | 362 | // and the parsing contains some error, I maintain the previous copy in the ast | ||
1774 | 363 | if (!(source_exists && result.is_edited && result.errors.size > 0)) | ||
1775 | 364 | { | ||
1776 | 365 | // if the source was already parsed and it's not opend in a edit window | ||
1777 | 366 | if (source_exists && !result.is_edited) { | ||
1778 | 367 | need_update = ast_source.update_last_modification_time(); | ||
1779 | 368 | } | ||
1780 | 369 | // this is important! | ||
1781 | 370 | // TODO: we shouldn't hold this reference lookup_source_file should return an unowned ref | ||
1782 | 371 | ast_source = null; | ||
1783 | 372 | if (need_update) { | ||
1784 | 373 | yield perform_merge_and_resolve (s, result, source_exists); | ||
1785 | 374 | this.file_parsed (this, result.source_path, result); | ||
1786 | 375 | } | ||
1787 | 376 | } else { | ||
1788 | 377 | Utils.trace ("engine %s: source (live buffer) with errors mantaining the previous parsing: %s", id, result.source_path); | ||
1789 | 378 | } | ||
1790 | 379 | break; // found the file | ||
1791 | 380 | } | ||
1792 | 381 | } | ||
1793 | 382 | |||
1794 | 383 | return result; | ||
1795 | 384 | } | ||
1796 | 385 | |||
1797 | 386 | private async void perform_merge_and_resolve (Vala.SourceFile s, ParseResult result, bool source_exists) | ||
1798 | 387 | { | ||
1799 | 388 | yield merge_vala_source (s, result, source_exists); | ||
1800 | 389 | yield resolve_ast (); | ||
1801 | 390 | } | ||
1802 | 391 | |||
1803 | 392 | private async void merge_vala_source (Vala.SourceFile s, ParseResult result, bool source_exists) | ||
1804 | 393 | { | ||
1805 | 394 | #if DEBUG | ||
1806 | 395 | GLib.Timer timer = new GLib.Timer (); | ||
1807 | 396 | double start_time = 0, elapsed; | ||
1808 | 397 | timer.start (); | ||
1809 | 398 | #endif | ||
1810 | 399 | var merger = new AstMerger (_ast); | ||
1811 | 400 | if (source_exists) { | ||
1812 | 401 | #if DEBUG | ||
1813 | 402 | Utils.trace ("engine %s: removing source (%p) %s", id, result, result.source_path); | ||
1814 | 403 | start_time = timer.elapsed (); | ||
1815 | 404 | #endif | ||
1816 | 405 | yield merger.remove_source_filename (result.source_path); | ||
1817 | 406 | #if DEBUG | ||
1818 | 407 | Utils.trace ("engine %s: removing source (%p) %s done %g", id, result, result.source_path, timer.elapsed () - start_time); | ||
1819 | 408 | #endif | ||
1820 | 409 | } | ||
1821 | 410 | #if DEBUG | ||
1822 | 411 | Utils.trace ("engine %s: merging source %s", id, result.source_path); | ||
1823 | 412 | start_time = timer.elapsed (); | ||
1824 | 413 | #endif | ||
1825 | 414 | yield merger.merge_vala_context (s, result.context, result.is_glib); | ||
1826 | 415 | result.context = null; // let's free some memory | ||
1827 | 416 | merger = null; | ||
1828 | 417 | #if DEBUG | ||
1829 | 418 | elapsed = timer.elapsed () - start_time; | ||
1830 | 419 | Utils.trace ("engine %s: merging source %s done %g %s", id, result.source_path, elapsed, elapsed > 0.7 ? " <== Warning" : ""); | ||
1831 | 420 | #endif | ||
1832 | 421 | } | ||
1833 | 422 | |||
1834 | 423 | private async void resolve_ast () | ||
1835 | 424 | { | ||
1836 | 425 | #if DEBUG | ||
1837 | 426 | GLib.Timer timer = new GLib.Timer (); | ||
1838 | 427 | double start_time = 0; | ||
1839 | 428 | timer.start (); | ||
1840 | 429 | //_ast.dump_symbols (); | ||
1841 | 430 | Utils.trace ("engine %s: resolving ast", id); | ||
1842 | 431 | start_time = timer.elapsed (); | ||
1843 | 432 | #endif | ||
1844 | 433 | var resolver = new SymbolResolver (); | ||
1845 | 434 | resolver.resolve (_ast); | ||
1846 | 435 | #if DEBUG | ||
1847 | 436 | Utils.trace ("engine %s: resolving ast done %g", id, timer.elapsed () - start_time); | ||
1848 | 437 | #endif | ||
1849 | 435 | } | 438 | } |
1850 | 436 | } | 439 | } |
1851 | 437 | } | 440 | } |
1852 | 438 | 441 | ||
1853 | === modified file 'plugins/completion/afrodite-provider/afrodite/parser.vala' | |||
1854 | --- plugins/completion/afrodite-provider/afrodite/parser.vala 2010-10-14 16:01:50 +0000 | |||
1855 | +++ plugins/completion/afrodite-provider/afrodite/parser.vala 2011-03-10 19:26:24 +0000 | |||
1856 | @@ -26,21 +26,15 @@ | |||
1857 | 26 | { | 26 | { |
1858 | 27 | public class Parser : GLib.Object | 27 | public class Parser : GLib.Object |
1859 | 28 | { | 28 | { |
1871 | 29 | public CodeContext context = null; | 29 | private CodeContext context = null; |
1872 | 30 | 30 | ||
1873 | 31 | public Parser (Vala.List<SourceItem> sources) | 31 | private unowned SourceItem _source; |
1874 | 32 | { | 32 | |
1864 | 33 | context = new Vala.CodeContext(); | ||
1865 | 34 | foreach (SourceItem source in sources) { | ||
1866 | 35 | add_source_item (source); | ||
1867 | 36 | } | ||
1868 | 37 | |||
1869 | 38 | } | ||
1870 | 39 | |||
1875 | 40 | public Parser.with_source (SourceItem source_item) | 33 | public Parser.with_source (SourceItem source_item) |
1876 | 41 | { | 34 | { |
1877 | 42 | context = new Vala.CodeContext(); | 35 | context = new Vala.CodeContext(); |
1878 | 43 | add_source_item (source_item); | 36 | add_source_item (source_item); |
1879 | 37 | _source = source_item; | ||
1880 | 44 | } | 38 | } |
1881 | 45 | 39 | ||
1882 | 46 | private void add_source_item (SourceItem source) | 40 | private void add_source_item (SourceItem source) |
1883 | @@ -99,6 +93,11 @@ | |||
1884 | 99 | parser.parse (context); | 93 | parser.parse (context); |
1885 | 100 | 94 | ||
1886 | 101 | CodeContext.pop (); | 95 | CodeContext.pop (); |
1887 | 96 | |||
1888 | 97 | parse_result.source_path = _source.path; | ||
1889 | 98 | parse_result.is_glib = _source.is_glib; | ||
1890 | 99 | parse_result.is_edited = _source.content != null; | ||
1891 | 100 | parse_result.context = context; | ||
1892 | 102 | return parse_result; | 101 | return parse_result; |
1893 | 103 | } | 102 | } |
1894 | 104 | } | 103 | } |
1895 | 105 | 104 | ||
1896 | === modified file 'plugins/completion/afrodite-provider/afrodite/parseresult.vala' | |||
1897 | --- plugins/completion/afrodite-provider/afrodite/parseresult.vala 2010-10-14 16:01:50 +0000 | |||
1898 | +++ plugins/completion/afrodite-provider/afrodite/parseresult.vala 2011-03-10 19:26:24 +0000 | |||
1899 | @@ -30,6 +30,11 @@ | |||
1900 | 30 | public Vala.List<string> errors = new Vala.ArrayList<string> (); | 30 | public Vala.List<string> errors = new Vala.ArrayList<string> (); |
1901 | 31 | public Vala.List<string> notes = new Vala.ArrayList<string> (); | 31 | public Vala.List<string> notes = new Vala.ArrayList<string> (); |
1902 | 32 | 32 | ||
1903 | 33 | public string source_path = null; | ||
1904 | 34 | public bool is_glib = false; | ||
1905 | 35 | public Vala.CodeContext context = null; | ||
1906 | 36 | public bool is_edited = false; | ||
1907 | 37 | |||
1908 | 33 | public override void warn (Vala.SourceReference? source, string message) | 38 | public override void warn (Vala.SourceReference? source, string message) |
1909 | 34 | { | 39 | { |
1910 | 35 | base.warn (source, message); | 40 | base.warn (source, message); |
1911 | 36 | 41 | ||
1912 | === modified file 'plugins/completion/afrodite-provider/afrodite/sourcefile.vala' | |||
1913 | --- plugins/completion/afrodite-provider/afrodite/sourcefile.vala 2010-10-14 16:01:50 +0000 | |||
1914 | +++ plugins/completion/afrodite-provider/afrodite/sourcefile.vala 2011-03-10 19:26:24 +0000 | |||
1915 | @@ -69,16 +69,10 @@ | |||
1916 | 69 | ~SourceFile () | 69 | ~SourceFile () |
1917 | 70 | { | 70 | { |
1918 | 71 | Utils.trace ("SourceFile destroying: %s", filename); | 71 | Utils.trace ("SourceFile destroying: %s", filename); |
1919 | 72 | #if DEBUG | ||
1920 | 73 | Utils.trace (" symbol count before destroy %d", parent.leaked_symbols.size); | ||
1921 | 74 | #endif | ||
1922 | 75 | while (symbols != null && symbols.size > 0) { | 72 | while (symbols != null && symbols.size > 0) { |
1923 | 76 | var symbol = symbols.get (0); | 73 | var symbol = symbols.get (0); |
1924 | 77 | remove_symbol (symbol); | 74 | remove_symbol (symbol); |
1925 | 78 | } | 75 | } |
1926 | 79 | #if DEBUG | ||
1927 | 80 | Utils.trace (" symbol count after destroy %d", parent.leaked_symbols.size); | ||
1928 | 81 | #endif | ||
1929 | 82 | Utils.trace ("SourceFile destroyed: %s", filename); | 76 | Utils.trace ("SourceFile destroyed: %s", filename); |
1930 | 83 | } | 77 | } |
1931 | 84 | 78 | ||
1932 | @@ -130,21 +124,11 @@ | |||
1933 | 130 | if (symbols == null) { | 124 | if (symbols == null) { |
1934 | 131 | symbols = new ArrayList<unowned Symbol> (); | 125 | symbols = new ArrayList<unowned Symbol> (); |
1935 | 132 | } | 126 | } |
1936 | 133 | assert (symbols.contains (symbol) == false); | ||
1937 | 134 | 127 | ||
1938 | 135 | symbols.add (symbol); | 128 | symbols.add (symbol); |
1939 | 136 | 129 | ||
1940 | 137 | |||
1941 | 138 | parent.symbols.set (symbol.fully_qualified_name, symbol); | 130 | parent.symbols.set (symbol.fully_qualified_name, symbol); |
1951 | 139 | #if DEBUG | 131 | parent.unresolved_symbols.add(symbol); |
1943 | 140 | // debug | ||
1944 | 141 | if (!parent.leaked_symbols.contains (symbol)) { | ||
1945 | 142 | //parent.leaked_symbols.add (symbol); | ||
1946 | 143 | symbol.weak_ref (this.on_symbol_destroy); | ||
1947 | 144 | } else { | ||
1948 | 145 | Utils.trace ("Symbol already added to the leak check: %s", symbol.fully_qualified_name); | ||
1949 | 146 | } | ||
1950 | 147 | #endif | ||
1952 | 148 | } | 132 | } |
1953 | 149 | 133 | ||
1954 | 150 | public void remove_symbol (Symbol symbol) | 134 | public void remove_symbol (Symbol symbol) |
1955 | @@ -157,6 +141,7 @@ | |||
1956 | 157 | 141 | ||
1957 | 158 | if (!symbol.has_source_references) { | 142 | if (!symbol.has_source_references) { |
1958 | 159 | parent.symbols.remove (symbol.fully_qualified_name); | 143 | parent.symbols.remove (symbol.fully_qualified_name); |
1959 | 144 | parent.unresolved_symbols.remove (symbol); | ||
1960 | 160 | if (symbol.parent != null) { | 145 | if (symbol.parent != null) { |
1961 | 161 | if (symbol.is_generic_type_argument) { | 146 | if (symbol.is_generic_type_argument) { |
1962 | 162 | symbol.parent.remove_generic_type_argument (symbol); | 147 | symbol.parent.remove_generic_type_argument (symbol); |
1963 | @@ -177,13 +162,5 @@ | |||
1964 | 177 | return symbols != null; | 162 | return symbols != null; |
1965 | 178 | } | 163 | } |
1966 | 179 | } | 164 | } |
1967 | 180 | |||
1968 | 181 | #if DEBUG | ||
1969 | 182 | private void on_symbol_destroy (Object obj) | ||
1970 | 183 | { | ||
1971 | 184 | parent.leaked_symbols.remove ((Symbol)obj); | ||
1972 | 185 | //Utils.trace ("symbol destroyed (%p)", obj); | ||
1973 | 186 | } | ||
1974 | 187 | #endif | ||
1975 | 188 | } | 165 | } |
1976 | 189 | } | 166 | } |
1977 | 190 | 167 | ||
1978 | === modified file 'plugins/completion/afrodite-provider/afrodite/sourcereference.vala' | |||
1979 | --- plugins/completion/afrodite-provider/afrodite/sourcereference.vala 2010-10-14 16:01:50 +0000 | |||
1980 | +++ plugins/completion/afrodite-provider/afrodite/sourcereference.vala 2011-03-10 19:26:24 +0000 | |||
1981 | @@ -23,13 +23,13 @@ | |||
1982 | 23 | 23 | ||
1983 | 24 | namespace Afrodite | 24 | namespace Afrodite |
1984 | 25 | { | 25 | { |
1986 | 26 | public class SourceReference : Object | 26 | public class SourceReference |
1987 | 27 | { | 27 | { |
1993 | 28 | public unowned SourceFile file { get; set; } | 28 | public unowned SourceFile file; |
1994 | 29 | public int first_line { get; set; } | 29 | public int first_line; |
1995 | 30 | public int last_line { get; set; } | 30 | public int last_line; |
1996 | 31 | public int first_column { get; set; } | 31 | public int first_column; |
1997 | 32 | public int last_column { get; set; } | 32 | public int last_column; |
1998 | 33 | 33 | ||
1999 | 34 | public bool contains_position (int line, int column) | 34 | public bool contains_position (int line, int column) |
2000 | 35 | { | 35 | { |
2001 | 36 | 36 | ||
2002 | === modified file 'plugins/completion/afrodite-provider/afrodite/symbol.vala' | |||
2003 | --- plugins/completion/afrodite-provider/afrodite/symbol.vala 2010-10-14 16:01:50 +0000 | |||
2004 | +++ plugins/completion/afrodite-provider/afrodite/symbol.vala 2011-03-10 19:26:24 +0000 | |||
2005 | @@ -24,7 +24,7 @@ | |||
2006 | 24 | 24 | ||
2007 | 25 | namespace Afrodite | 25 | namespace Afrodite |
2008 | 26 | { | 26 | { |
2010 | 27 | public class Symbol : Object | 27 | public class Symbol |
2011 | 28 | { | 28 | { |
2012 | 29 | public static VoidType VOID = new VoidType (); | 29 | public static VoidType VOID = new VoidType (); |
2013 | 30 | public static EllipsisType ELLIPSIS = new EllipsisType (); | 30 | public static EllipsisType ELLIPSIS = new EllipsisType (); |
2014 | @@ -346,7 +346,7 @@ | |||
2015 | 346 | return null; | 346 | return null; |
2016 | 347 | } | 347 | } |
2017 | 348 | 348 | ||
2019 | 349 | public DataType? lookup_datatype_for_variable (CompareMode mode, string name, SymbolAccessibility access = SymbolAccessibility.ANY) | 349 | public DataType? lookup_datatype_for_variable_name (CompareMode mode, string name, SymbolAccessibility access = SymbolAccessibility.ANY) |
2020 | 350 | { | 350 | { |
2021 | 351 | if (has_local_variables) { | 351 | if (has_local_variables) { |
2022 | 352 | foreach (DataType d in local_variables) { | 352 | foreach (DataType d in local_variables) { |
2023 | @@ -355,7 +355,7 @@ | |||
2024 | 355 | } | 355 | } |
2025 | 356 | } | 356 | } |
2026 | 357 | } | 357 | } |
2028 | 358 | 358 | ||
2029 | 359 | // search in symbol parameters | 359 | // search in symbol parameters |
2030 | 360 | if (has_parameters) { | 360 | if (has_parameters) { |
2031 | 361 | foreach (DataType type in parameters) { | 361 | foreach (DataType type in parameters) { |
2032 | @@ -365,6 +365,11 @@ | |||
2033 | 365 | } | 365 | } |
2034 | 366 | } | 366 | } |
2035 | 367 | 367 | ||
2036 | 368 | return null; | ||
2037 | 369 | } | ||
2038 | 370 | |||
2039 | 371 | public DataType? lookup_datatype_for_symbol_name (CompareMode mode, string name, SymbolAccessibility access = SymbolAccessibility.ANY) | ||
2040 | 372 | { | ||
2041 | 368 | if (has_children) { | 373 | if (has_children) { |
2042 | 369 | foreach (Symbol s in this.children) { | 374 | foreach (Symbol s in this.children) { |
2043 | 370 | if ((s.access & access) != 0 | 375 | if ((s.access & access) != 0 |
2044 | @@ -377,7 +382,7 @@ | |||
2045 | 377 | if (has_base_types) { | 382 | if (has_base_types) { |
2046 | 378 | foreach (DataType d in this.base_types) { | 383 | foreach (DataType d in this.base_types) { |
2047 | 379 | if (d.symbol != null) { | 384 | if (d.symbol != null) { |
2049 | 380 | var r = d.symbol.lookup_datatype_for_variable (mode, name, | 385 | var r = d.symbol.lookup_datatype_for_symbol_name (mode, name, |
2050 | 381 | SymbolAccessibility.INTERNAL | SymbolAccessibility.PROTECTED | SymbolAccessibility.PROTECTED); | 386 | SymbolAccessibility.INTERNAL | SymbolAccessibility.PROTECTED | SymbolAccessibility.PROTECTED); |
2051 | 382 | if (r != null) { | 387 | if (r != null) { |
2052 | 383 | return d; | 388 | return d; |
2053 | @@ -387,15 +392,24 @@ | |||
2054 | 387 | } | 392 | } |
2055 | 388 | return null; | 393 | return null; |
2056 | 389 | } | 394 | } |
2057 | 395 | |||
2058 | 396 | public DataType? lookup_datatype_for_name (CompareMode mode, string name, SymbolAccessibility access = SymbolAccessibility.ANY) | ||
2059 | 397 | { | ||
2060 | 398 | var result = lookup_datatype_for_variable_name (mode, name, access); | ||
2061 | 399 | if (result != null) | ||
2062 | 400 | return result; | ||
2063 | 401 | |||
2064 | 402 | return lookup_datatype_for_symbol_name (mode, name, access); | ||
2065 | 403 | } | ||
2066 | 390 | 404 | ||
2068 | 391 | public DataType? scope_lookup_datatype_for_variable (CompareMode mode, string name) | 405 | public DataType? scope_lookup_datatype_for_name (CompareMode mode, string name) |
2069 | 392 | { | 406 | { |
2071 | 393 | DataType result = lookup_datatype_for_variable (mode, name); | 407 | DataType result = lookup_datatype_for_name (mode, name); |
2072 | 394 | 408 | ||
2073 | 395 | if (result == null) { | 409 | if (result == null) { |
2074 | 396 | 410 | ||
2075 | 397 | if (this.parent != null) { | 411 | if (this.parent != null) { |
2077 | 398 | result = this.parent.scope_lookup_datatype_for_variable (mode, name); | 412 | result = this.parent.scope_lookup_datatype_for_name (mode, name); |
2078 | 399 | } | 413 | } |
2079 | 400 | 414 | ||
2080 | 401 | if (result == null) { | 415 | if (result == null) { |
2081 | @@ -405,7 +419,7 @@ | |||
2082 | 405 | if (s.file.has_using_directives) { | 419 | if (s.file.has_using_directives) { |
2083 | 406 | foreach (var u in s.file.using_directives) { | 420 | foreach (var u in s.file.using_directives) { |
2084 | 407 | if (!u.unresolved) { | 421 | if (!u.unresolved) { |
2086 | 408 | result = u.symbol.lookup_datatype_for_variable (mode, name, SymbolAccessibility.INTERNAL | SymbolAccessibility.PUBLIC); | 422 | result = u.symbol.lookup_datatype_for_symbol_name (mode, name, SymbolAccessibility.INTERNAL | SymbolAccessibility.PUBLIC); |
2087 | 409 | if (result != null) { | 423 | if (result != null) { |
2088 | 410 | break; | 424 | break; |
2089 | 411 | } | 425 | } |
2090 | @@ -522,7 +536,6 @@ | |||
2091 | 522 | generic_type_arguments = new ArrayList<Symbol> (); | 536 | generic_type_arguments = new ArrayList<Symbol> (); |
2092 | 523 | } | 537 | } |
2093 | 524 | 538 | ||
2094 | 525 | assert (generic_type_arguments.contains(sym) == false); | ||
2095 | 526 | //debug ("added generic %s to %s", sym.name, this.fully_qualified_name); | 539 | //debug ("added generic %s to %s", sym.name, this.fully_qualified_name); |
2096 | 527 | //Utils.trace ("add generic type args symbol %s: %s", _fully_qualified_name, sym.fully_qualified_name); | 540 | //Utils.trace ("add generic type args symbol %s: %s", _fully_qualified_name, sym.fully_qualified_name); |
2097 | 528 | generic_type_arguments.add (sym); | 541 | generic_type_arguments.add (sym); |
2098 | @@ -623,16 +636,18 @@ | |||
2099 | 623 | } | 636 | } |
2100 | 624 | } | 637 | } |
2101 | 625 | 638 | ||
2103 | 626 | public SourceReference? lookup_source_reference_filename (string filename) | 639 | public unowned SourceReference? lookup_source_reference_filename (string filename) |
2104 | 627 | { | 640 | { |
2105 | 641 | unowned SourceReference? result = null; | ||
2106 | 628 | if (has_source_references) { | 642 | if (has_source_references) { |
2107 | 629 | foreach (SourceReference reference in source_references) { | 643 | foreach (SourceReference reference in source_references) { |
2108 | 630 | if (reference.file.filename == filename) | 644 | if (reference.file.filename == filename) |
2110 | 631 | return reference; | 645 | result = reference; |
2111 | 646 | break; | ||
2112 | 632 | } | 647 | } |
2113 | 633 | } | 648 | } |
2114 | 634 | 649 | ||
2116 | 635 | return null; | 650 | return result; |
2117 | 636 | } | 651 | } |
2118 | 637 | 652 | ||
2119 | 638 | public SourceReference? lookup_source_reference_sourcefile (SourceFile source) | 653 | public SourceReference? lookup_source_reference_sourcefile (SourceFile source) |
2120 | @@ -1053,7 +1068,6 @@ | |||
2121 | 1053 | if (_specialized_symbols == null) | 1068 | if (_specialized_symbols == null) |
2122 | 1054 | _specialized_symbols = new Vala.ArrayList<Symbol> (); | 1069 | _specialized_symbols = new Vala.ArrayList<Symbol> (); |
2123 | 1055 | 1070 | ||
2124 | 1056 | assert (_specialized_symbols.contains (item) == false); | ||
2125 | 1057 | _specialized_symbols.add (item); | 1071 | _specialized_symbols.add (item); |
2126 | 1058 | item.generic_parent = this; | 1072 | item.generic_parent = this; |
2127 | 1059 | } | 1073 | } |
2128 | @@ -1061,7 +1075,6 @@ | |||
2129 | 1061 | public void remove_specialized_symbol (Symbol? item) | 1075 | public void remove_specialized_symbol (Symbol? item) |
2130 | 1062 | { | 1076 | { |
2131 | 1063 | assert (item != this); | 1077 | assert (item != this); |
2132 | 1064 | assert (_specialized_symbols.contains (item)); | ||
2133 | 1065 | 1078 | ||
2134 | 1066 | _specialized_symbols.remove (item); | 1079 | _specialized_symbols.remove (item); |
2135 | 1067 | if (item.generic_parent == this) | 1080 | if (item.generic_parent == this) |
2136 | 1068 | 1081 | ||
2137 | === modified file 'plugins/completion/afrodite-provider/afrodite/symbolresolver.vala' | |||
2138 | --- plugins/completion/afrodite-provider/afrodite/symbolresolver.vala 2010-10-14 16:01:50 +0000 | |||
2139 | +++ plugins/completion/afrodite-provider/afrodite/symbolresolver.vala 2011-03-10 19:26:24 +0000 | |||
2140 | @@ -44,13 +44,12 @@ | |||
2141 | 44 | 44 | ||
2142 | 45 | // first resolve the using directives | 45 | // first resolve the using directives |
2143 | 46 | if (_ast.has_source_files) { | 46 | if (_ast.has_source_files) { |
2144 | 47 | Symbol dummy; | ||
2145 | 48 | foreach (SourceFile file in _ast.source_files) { | 47 | foreach (SourceFile file in _ast.source_files) { |
2146 | 49 | if (file.has_using_directives) { | 48 | if (file.has_using_directives) { |
2147 | 50 | foreach (DataType using_directive in file.using_directives) { | 49 | foreach (DataType using_directive in file.using_directives) { |
2148 | 51 | // | 50 | // |
2149 | 52 | if (using_directive.unresolved) { | 51 | if (using_directive.unresolved) { |
2151 | 53 | using_directive.symbol = _ast.lookup (using_directive.type_name, out dummy); | 52 | using_directive.symbol = _ast.lookup (using_directive.type_name); |
2152 | 54 | if (using_directive.unresolved) | 53 | if (using_directive.unresolved) |
2153 | 55 | message ("file %s - can't resolve using directive: %s", file.filename, using_directive.type_name); | 54 | message ("file %s - can't resolve using directive: %s", file.filename, using_directive.type_name); |
2154 | 56 | } | 55 | } |
2155 | @@ -59,8 +58,12 @@ | |||
2156 | 59 | } | 58 | } |
2157 | 60 | } | 59 | } |
2158 | 61 | 60 | ||
2161 | 62 | if (ast.root.has_children) | 61 | if (ast.unresolved_symbols.size > 0) { |
2162 | 63 | visit_symbols (ast.root.children); | 62 | Afrodite.Utils.trace ("(symbol resolver): symbols to resolve %d", ast.unresolved_symbols.size); |
2163 | 63 | visit_symbols (ast.unresolved_symbols); | ||
2164 | 64 | Afrodite.Utils.trace ("(symbol resolver): unresolved symbol after resolve process %d", ast.unresolved_symbols.size); | ||
2165 | 65 | } | ||
2166 | 66 | |||
2167 | 64 | } | 67 | } |
2168 | 65 | 68 | ||
2169 | 66 | private Symbol? resolve_type (Symbol symbol, DataType type) | 69 | private Symbol? resolve_type (Symbol symbol, DataType type) |
2170 | @@ -303,7 +306,52 @@ | |||
2171 | 303 | 306 | ||
2172 | 304 | } | 307 | } |
2173 | 305 | } | 308 | } |
2175 | 306 | 309 | ||
2176 | 310 | private bool visit_symbol (Symbol symbol) | ||
2177 | 311 | { | ||
2178 | 312 | //print_symbol (symbol); | ||
2179 | 313 | bool resolved = true; | ||
2180 | 314 | |||
2181 | 315 | // resolving base types | ||
2182 | 316 | if (symbol.has_base_types) { | ||
2183 | 317 | foreach (DataType type in symbol.base_types) { | ||
2184 | 318 | if (type.unresolved) { | ||
2185 | 319 | type.symbol = resolve_type (symbol, type); | ||
2186 | 320 | resolved &= !type.unresolved; | ||
2187 | 321 | } | ||
2188 | 322 | } | ||
2189 | 323 | } | ||
2190 | 324 | // resolving return type | ||
2191 | 325 | if (symbol.return_type != null) { | ||
2192 | 326 | if (symbol.return_type.unresolved) { | ||
2193 | 327 | symbol.return_type.symbol = resolve_type (symbol, symbol.return_type); | ||
2194 | 328 | resolved &= !symbol.return_type.unresolved; | ||
2195 | 329 | } | ||
2196 | 330 | } | ||
2197 | 331 | |||
2198 | 332 | // resolving symbol parameters | ||
2199 | 333 | if (symbol.has_parameters) { | ||
2200 | 334 | foreach (DataType type in symbol.parameters) { | ||
2201 | 335 | if (type.unresolved) { | ||
2202 | 336 | type.symbol = resolve_type (symbol, type); | ||
2203 | 337 | resolved &= !type.unresolved; | ||
2204 | 338 | } | ||
2205 | 339 | } | ||
2206 | 340 | } | ||
2207 | 341 | // resolving local variables | ||
2208 | 342 | if (symbol.has_local_variables) { | ||
2209 | 343 | foreach (DataType type in symbol.local_variables) { | ||
2210 | 344 | if (type.unresolved) { | ||
2211 | 345 | resolve_symbol (symbol, type); | ||
2212 | 346 | resolved &= !type.unresolved; | ||
2213 | 347 | } | ||
2214 | 348 | } | ||
2215 | 349 | } | ||
2216 | 350 | |||
2217 | 351 | return resolved; | ||
2218 | 352 | } | ||
2219 | 353 | |||
2220 | 354 | /* | ||
2221 | 307 | private void visit_symbol (Symbol symbol) | 355 | private void visit_symbol (Symbol symbol) |
2222 | 308 | { | 356 | { |
2223 | 309 | //print_symbol (symbol); | 357 | //print_symbol (symbol); |
2224 | @@ -342,13 +390,20 @@ | |||
2225 | 342 | if (symbol.has_children) { | 390 | if (symbol.has_children) { |
2226 | 343 | visit_symbols (symbol.children); | 391 | visit_symbols (symbol.children); |
2227 | 344 | } | 392 | } |
2229 | 345 | } | 393 | }*/ |
2230 | 346 | 394 | ||
2232 | 347 | private void visit_symbols (Vala.List<Afrodite.Symbol> symbols) | 395 | private void visit_symbols (Vala.List<unowned Afrodite.Symbol> symbols) |
2233 | 348 | { | 396 | { |
2234 | 397 | Vala.List<unowned Afrodite.Symbol> resolved = new Vala.ArrayList<unowned Afrodite.Symbol>(); | ||
2235 | 398 | |||
2236 | 349 | foreach (Symbol symbol in symbols) { | 399 | foreach (Symbol symbol in symbols) { |
2238 | 350 | visit_symbol (symbol); | 400 | if (visit_symbol (symbol)) { |
2239 | 401 | resolved.add (symbol); | ||
2240 | 402 | } | ||
2241 | 351 | } | 403 | } |
2242 | 404 | |||
2243 | 405 | foreach (Symbol symbol in resolved) | ||
2244 | 406 | symbols.remove(symbol); | ||
2245 | 352 | } | 407 | } |
2246 | 353 | } | 408 | } |
2247 | 354 | } | 409 | } |
Check this a lot because Afrodite could crash but I cannot reproduce it.
Thanks in advance.